Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion src/MyMath.java
Original file line number Diff line number Diff line change
@@ -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));
}
}