import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
System.out.println("请输入你猜测的数字(1-1000),退出请按0");
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
int num = (int)(Math.random()*1000+1);
while(i!=num){
if (i==0){
break;
}else if (i>num){
System.out.println("太大了");
}else
System.out.println("太小了");
System.out.println("请输入你猜测的数字(1-1000),退出请按0");
i = scanner.nextInt();
}
if(i==num){
System.out.println("恭喜,你猜对了");
}else
System.out.println("真遗憾,欢迎再来挑战!");
}
}
转载于:https://my.oschina.net/u/2311975/blog/372534