package testrandom;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Random ra = new Random();
Scanner sc = new Scanner(System.in);
int temp = ra.nextInt(10);
System.out.println(temp);
String s = "";
int count = 0;
while(true){
System.out.println("请通过键盘输入您猜的数字:");
s = sc.next();
if(s.matches("//d*"))
{
int in = Integer.parseInt(s);
if(in == temp)
{
System.out.println("您猜对了!");
count +=1;
break;
}
else
{
System.out.println("啊呀呀,还是不对,再来一次?!");
count++;
}
}
else
{
System.out.println("请输入数字格式!");
count++;
continue;
}
}
if(count<=3)
{
System.out.println("您只猜了 " + count + " 次");
}
else{
System.out.println("多多努力,您总计猜了 " + count + " 次");
}
}
}