package day2_3;
import java.util.Scanner;
public class 练习2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int guess =(int)(Math.random()*1000+1);//随机生成一个数
System.out.println(guess);
System.out.println("退出游戏请按0");
System.out.println("猜吧");
int num = scan.nextInt();//用户输入一个数
while(num!=guess){
if(guess==0){
break;
}else if(num>guess){
System.out.println("太大了");
}else{
System.out.println("太小了");
}
System.out.println("猜吧");
num = scan.nextInt();
}
if(num==guess){
System.out.println("恭喜你猜对了");
}else if(guess==0){
System.out.println("很遗憾,下次再来吧!");
}
}
}
ziom
相关分类