From c291e4de2364354cc499e42dca5fc323c12490dc Mon Sep 17 00:00:00 2001 From: FinnCl4rk Date: Sat, 21 Oct 2023 10:16:16 -0700 Subject: [PATCH] Completed Assignment 007 --- .idea/misc.xml | 2 +- src/MyMath.java | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..a346fd7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/MyMath.java b/src/MyMath.java index 7da9a29..aa2d6e0 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -1,7 +1,28 @@ +/*Finn Clark +10/21/23 +CIS - 12 +Hartman +* */ import java.util.Scanner; public class MyMath { - public static void main(String[] args) { + public static int gCF(int x, int y) { + + while (y != 0){ + int z = y; + y = x%y; + x = z; + }return x; + } + + public static void main(String[] args){ + Scanner in = new Scanner(System.in); + System.out.println("Enter a number: "); + int numerator = Integer.parseInt(in.nextLine()); + System.out.println("Enter another number to find their greatest common factor: "); + int denominator = Integer.parseInt(in.nextLine()); + int gcf = gCF(numerator, denominator); + System.out.printf("The greatest common factor of %d and %d is %d", numerator, denominator, gcf); + } } -}