From b97ee25b69da2102783170758ed629a220f20336 Mon Sep 17 00:00:00 2001 From: lance Date: Thu, 19 Oct 2023 10:36:35 -0700 Subject: [PATCH 1/3] Assignment-007-Steven Fraga --- .idea/misc.xml | 2 +- src/MyMath.java | 18 +++++++++++++++++- 2 files changed, 18 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..416c986 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -1,7 +1,23 @@ 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); + System.out.println("Give a positive number: "); + int a = Integer.parseInt(s.nextLine()); + System.out.println("Give a positive number: "); + int b = Integer.parseInt(s.nextLine()); + System.out.println(gCF(a,b)); } } From 16ff6f8857b3d0deaff0a246e0a43a720c22cae7 Mon Sep 17 00:00:00 2001 From: lance Date: Thu, 19 Oct 2023 11:03:55 -0700 Subject: [PATCH 2/3] Assignment-007-Steven Fraga --- src/MyMath.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/MyMath.java b/src/MyMath.java index 416c986..0f599fb 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -14,10 +14,19 @@ public static int gCF(int a, int b) { } public static void main(String[] args) { Scanner s = new Scanner(System.in); - System.out.println("Give a positive number: "); - int a = Integer.parseInt(s.nextLine()); - System.out.println("Give a positive number: "); - int b = Integer.parseInt(s.nextLine()); - System.out.println(gCF(a,b)); + String input1, input2 = null, 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; + } + } } From 8e0ac60acfd39291c9fdc925b7c3e2f26feb6c73 Mon Sep 17 00:00:00 2001 From: lance Date: Thu, 19 Oct 2023 11:05:06 -0700 Subject: [PATCH 3/3] Assignment-007-Steven Fraga --- src/MyMath.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MyMath.java b/src/MyMath.java index 0f599fb..b02434f 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -14,7 +14,8 @@ public static int gCF(int a, int b) { } public static void main(String[] args) { Scanner s = new Scanner(System.in); - String input1, input2 = null, message = "Give me a %snumber (Q to quit):"; + 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) {