为什么我输出的结果,一直都是太小了。死循环下去。

来源:3-2 案例:猜字游戏

仲夏残阳

2017-07-19 18:52:14

	public static void main(String[] args) {
		int mubiao = 65;
		int shuru;
		System.out.println("输入一个数");
		Scanner s =new Scanner(System.in);
		shuru = s.nextInt();
		while(mubiao!=shuru){
			
			
			if(shuru>mubiao){
				System.out.println("太大");
			}else if (shuru<mubiao){
				System.out.println("太小");
			}
		
		

}
		System.out.println("zhengqu ");
}
}


写回答

1回答

耶嘿呦呦奥

2017-07-19

当从键盘输入一个比65小的数后,进行循环判断,满足条件执行循环,输出太小。循环会继续执行,此时shuru变量的值并没有改变,因此循环会一直执行下去。所以需要在循环的下面在写一条语句shuru=s.nextInt();

如果解决了你的疑惑,请采纳,祝学习愉快~

0

0 学习 · 14452 问题

查看课程