为什么输出count是零?
public static void main(String[] str){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int r=n%m;
int count = 0;
while(r!=0){
if(n>m){
count++;
swap(n,m);//交换值
}
else if(m==0){
count++;
System.out.println();
}
else{
count++;
//省略
}
System.out.println(count);
}
}
n和m你输入的什么值呢
能打印下n.m.r的值么
既然你每个条件分支里都要执行count++,为什么不把它拿到外面来,直接放到while里面呢
如果它是0,说明while一开始根本就没进去
-=-=-==
学编程先学调试,设断点,多放print,看你的代码到底走到哪去了,过程值又是多少,是否跟你预期相一致
你最先测试的就是m和n到底是不是你输入的值
在第五行打个断点,用debug 运行,自己跟代码就知道了
因为r等于了0呀,