Last active
June 10, 2017 16:38
-
-
Save jshinevar/db2d8c308bc4a556c350d8c25d741260 to your computer and use it in GitHub Desktop.
Greatest Common Divisor Brute Force Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* Created by James Shinevar on 6/10/17. | |
* james.shinevar@gmail.com | |
* http://jamesshinevar.com | |
*/ | |
public class GCDMain { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.println("Please enter your first number:"); | |
long FirstNumber = input.nextLong(); | |
input.nextLine(); | |
System.out.println("Please enter your second number:"); | |
long SecondNumber = input.nextLong(); | |
input.nextLine(); | |
System.out.println("SlowGCD is: " + SlowGCD(FirstNumber,SecondNumber)); | |
} | |
private static long SlowGCD(long FirstNumber, long SecondNumber) { | |
long GCD = 0; | |
for (long counter = 1; counter < (FirstNumber + SecondNumber); counter++) { | |
if (FirstNumber % counter == 0) { | |
if (SecondNumber % counter == 0) { | |
GCD = counter; | |
} | |
} | |
} | |
return GCD; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment