Scanner scan = new Scanner(System.in);
System.out.println("输入两个数用\",\"分隔");
String[] s = scan.nextLine().split(",");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
int count = a>=b?b:a;
for(int i =1;i<=count;i++){
if(a%i==0 && b%i==0){
System.out.println(a+"和"+b+"的公约数有"+i);
}
}
温馨提示:内容为网友见解,仅供参考