From ba479fd77ded19de13e8efee4b5ab87c19b8bacd Mon Sep 17 00:00:00 2001 From: Lina Date: Sun, 10 Dec 2023 01:11:00 -0800 Subject: [PATCH] completed assignment 007 --- .idea/misc.xml | 2 +- src/MyMath.java | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..ce297c6 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..a6be0af 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -1,7 +1,39 @@ +/** + * + * @author Trevor Hartman + * @author Angelina Perez + */ import java.util.Scanner; - 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 %snumber (Q to quit):"; + System.out.printf(String.format(message, "")); + while (!(input1 = s.nextLine()).equals("Q")) { + if (input2 == null) { + input2 = input1; + System.out.printf(String.format(message, "second ")); + continue; + } + System.out.printf("GCF of %s and %s is %d%n", + input1, input2, gCF(Integer.parseInt(input1),Integer.parseInt(input2))); + + System.out.printf(String.format(message, "")); + input2 = null; + } } } +