package qsy;
import java.util.Scanner;
import java.util.Random;
public class HiLo
{
public static void main(String[] args)
{Random generator=new Random();
int number,count,key=12;String another="y";
Scanner scan=new Scanner(System.in);
while(another.equals("y"))
{count=1;
System.out.println("请输入一个您所猜的1-1000的数");
number=scan.nextInt();
scan.nextLine();
System.out.println("您输入的数为:"+number);
key=generator.nextInt(1000)+1;
while(number!=0)
{
while(number<key&&number!=0)
{System.out.println("请输入一个更大的数,输入0则退出");
number=scan.nextInt();scan.nextLine();count++;}
while(number>key&&number!=0)
{System.out.println("请输入一个更小的数,输入0则退出");
number=scan.nextInt();scan.nextLine();count++;}
if(number==key&&number!=0)
{ System.out.println("正确!");
System.out.println("您总共猜的次数为:"+count);
System.out.println("是否重新玩一遍,如果是则输入0");
number=scan.nextInt();
}
}
scan.nextLine();
System.out.println("请输入y重新开始游戏");
another=scan.nextLine();
}
}
}