GCDNum.java
This program was created to get the greatest common divisor of two integer values.
Since greatest common divisor are numbers that are less than themselves, you would need to grab values from a range of 0 to the first integer or the second integer and check if that number is divisible by both.
The code has been modified slightly and now uploaded to the site.
Code Snippet
// Link to Challenge: https://edabit.com/challenge/jrh488nh4CyDmwMre
public class GCDNum {
public static void main(String[] args){
int result = gcd(32, 8);
int result2 = gcd(8, 12);
int result3 = gcd(17, 13);
System.out.println(result);
System.out.println(result2);
System.out.println(result3);
}
public static int gcd(int n1, int n2){
int divisor = 0;
for (int i = 1; i <= n1 && i <= n2; ++i){
if (n1 % i == 0 && n2 % i == 0){
divisor = i;
}
}
return divisor;
}
}