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