import java.util.Scanner;
public class caizi {
public static void main(String[] args) {
int num=(int)(Math.random()*1000)+1;
System.out.println("请输入你猜测的数字(1-1000),退出请按0:");
Scanner sc=new Scanner(System.in);
int guest=sc.nextInt();
while (guest!=num){
if(guest==0){
break;
}else if(guest>num){
System.out.println("太大了");
}else{
System.out.println("太小了");
}
System.out.println("请输入你猜测的数字(1-1000),退出请按0:");
guest=sc.nextInt();
}
if (guest==num){
System.out.println("恭喜你,猜对了!");
}else{
System.out.println("真遗憾,下次再挑战吧!");
}
sc.close();
}
} |
|