找最大公约数

import java.util.Scanner;
public class chapt3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter n1 and n2:");
int d=1;   //d为公约数
int n1 = input.nextInt();
int n2 = input.nextInt();
if (n1>n2)
d=n2;
else if (n1<n2)
d=n1;
else
System.out.println("Please the right number");
while(d>1){
if(n1%d == 0 && n2 % d == 0){
System.out.println(d);
break;
}
d=d-1;
}
}
}

你可能感兴趣的:(java)