diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..844b5c4 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..28bb6da 100644 --- a/src/MyMath.java +++ b/src/MyMath.java @@ -1,7 +1,34 @@ import java.util.Scanner; public class MyMath { - + /** + * A simple recreation of Euclid's GCF algorithm + * @param in1 First integer input + * @param in2 Second integer input + * @return The greatest common factor of in1 and in2 + */ + public static int gcf(int in1, int in2){ + int in3; + while(in2 != 0){ + if(in1 > in2) + in3 = in2; + else in2 = in2 % in1; + in3 = in2; + in2 = in1 % in2; + in1 = in3; + } + return in1; + } public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int in1, in2; + + System.out.println("Please enter two integers to find their greatest common factor"); + System.out.print("First integer: "); + in1 = Integer.parseInt(s.nextLine()); + System.out.print("Second integer: "); + in2 = Integer.parseInt(s.nextLine()); + + System.out.printf("The greatest common factor of %d and %d is %d", in1, in2, gcf(in1, in2)); } }