import java.util.Random;
import java.util.Scanner;
class Demo
{
public static void main(String [] args)
{ /* for(int i = 0 ; i < 10 ;i++)
{
Random r = new Random();
System.out.println(r.nextInt(10)+1) ;
}*/
Random r = new Random();
int a = r.nextInt(10)+1 ;
int count = 0 ;
while(true)
{
System.out.println("请输入一个数!");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
System.out.println("您输入的是:"+i);
System.out.println("------------------");
if ( i == a )
{
System.out.println("您猜对了!");
break;
}
else if(i > a)
{
System.out.println("您猜大了!");
System.out.println("------------------");
count++;
}
else
{
System.out.println("您猜小了!");
count++;
System.out.println("------------------");
}
if(count == 3)
{
System.out.println("你的次数用完了! 欢迎下次继续!");
break;
}
}
}
}
|
|