I'm doing some self-taught Java, but can't seem to figure out the issue in this loop:
The question was to find the greatest common divisor of two integers n1 and n2 where d is the lesser value. The method is to decrement d until a GCD or it reaches 1...here's where I'm at so far:
Scanner input = new Scanner(System.in);
System.out.println("Please enter two integers: ");
int n1 = input.nextInt();
int n2 = input.nextInt();
int d = 0;
int temp = 0;
//finds the lowest value
if(n1 < n2) {
temp = n1;
n1 = n2;
n2 = temp;
}
for(d = n1;(n1 % d !=0 && n2 % d != 0);d--) {
}
System.out.println("The GCD of " + n1 + " and " + n2 + " is " + d);
Any pointers?