public class GuessNumber {
public static void main(String[] args) {
Random ran = new Random();
int randomInt = ran.nextInt(10)+1;
Scanner sc
= new Scanner(System.in);
int count = 0;
while(count<3){
System.out.println("请输入数字,1-10之间");
int guessInt = sc.nextInt();
if(guessInt > randomInt){
System.out.println("猜大了,请重新输入,剩余次数为:"+(3-count-1));
count++;
}else if(guessInt < randomInt){
System.out.println("猜小了,请重新输入,剩余次数为:"+(3-count-1));
count++;
}else{
System.out.println("恭喜你,猜对了");
break;
}
}
System.out.println("次数用尽,正确答案为:"+randomInt);
}
}