import java.util.Scanner;
public class GuessNumbertest {
public static void main(String[] args){
int tureNumber =(int)(Math.random()*100)+1;
int x = 1;
while (true){
x++;
Scanner sc = new Scanner(System.in);
System.out.println("请输入你猜的数字(1-100)");
int number = sc.nextInt();
if(number > tureNumber && x<11){
System.out.println("你猜的"+number+"大了");
}
else if (number < tureNumber && x<11){
System.out.println("你猜的"+number+"小了");
}
else if(number == tureNumber && x<11){
System.out.println("你猜对了,并且使用了"+x+"次机会");
break;
}
else{
System.out.println("很抱歉,你的十次机会用完了,游戏失败");
break;
}
}
}
}
|
|