import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* Description:
* User: Wu Ruixi
* Date:2019/10/17
* Time:21:21
**/
public class Work2_6 {
// 求两个正整数的最大公约数
public static void main(String[] args) {
System.out.print("请输入a和b:");
Scanner scan = new Scanner(System.in);//以空格作为分隔符
int a = scan.nextInt();
int b = scan.nextInt();
int middle1,middle2,middle3;
middle1=a;
middle2=b;
middle3=0;
for (int i=0;i<i+1;i++) {
middle3=middle1%middle2;
if(middle3==0)
break;
else{
middle1=middle2;
middle2=middle3;
}
}
System.out.println("最大公约数为:"+middle2);
scan.close();
}
}
求两个正整数的最大公约数
最新推荐文章于 2022-03-15 15:01:44 发布