From 2089d4e95fa522389b9f07f1857b9436e0610c7c Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 19 Oct 2023 11:08:37 -0700 Subject: [PATCH] Ethan J --- .idea/misc.xml | 2 +- src/MyMath.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..5d30da4 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..408a890 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -2,6 +2,35 @@ public class MyMath { + public static int gcf(int a, int b) { + while (b != 0) ; + { + if (a > b) { + int c = b; + b = a % b; + a = c; + } else{ + b = b % a; + } + } + return a; + } public static void main(String[] args) { + Scanner s = new Scanner(System.in); + String input1, input2 = null; +String message = "Give me a %%s number (Q to quit): "; + + System.out.println(String.format(message, "")); + while(!(input1 = s.nextLine()).equals("Q")){ + if(input2 == null) { + input2 = input1; + System.out.println(String.format(message, "Second ")); + continue; + } + System.out.printf("GCF of %d is %d%n", input1, input2, + gcf(Integer.parseInt(input1),Integer.parseInt(input2))); + + System.out.println(String.format(message, "")); + } } }