import java.util.Scanner;
public class NumberGuessV02 { public static void main(String[] args){ //生成一个随机数 int num = (int)(Math.random()*1000)+1; //准备输入 Scanner sc = new Scanner(System.in); int guest = -1; do{ System.out.println("请输入要猜的数字,按0退出"); guest = sc.nextInt(); //判断输入0终止 if(guest == 0){ break; }else if (guest > num){ System.out.println("太大了"); }else{ System.out.println("太小了"); } }while (guest != num); //提示最终结果 if(guest == num){ System.out.println("恭喜猜对了"); }else{ System.out.println("很遗憾,下次挑战"); } sc.close(); }}