From 839ef06712314a32a5ec8d30f4ee76d43555080e Mon Sep 17 00:00:00 2001 From: ishwar Date: Fri, 15 Dec 2023 21:41:12 -0800 Subject: [PATCH] assignment 7 redone --- .idea/misc.xml | 2 +- src/MyMath.java | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..045943f 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..d253b7c 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -2,6 +2,38 @@ public class MyMath { - public static void main(String[] args) { + public static int gcf(int a, int b) { + while (b != 0) { + if (a > b) { + int temp = b; + b = a % b; + a = temp; + } else { + int temp = a; + a = b; + b = temp % b; + } + } + + return a; + } + + // method for testing + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + + System.out.print("first number: "); + int num1 = scanner.nextInt(); + + System.out.print("second number: "); + int num2 = scanner.nextInt(); + + + int result = gcf(num1, num2); + System.out.println("The GCF of " + num1 + " and " + num2 + " is: " + result); + + + } } -} +