public class CaiShuGame{
public static void main(String[] args) {
int num = (int)(Math.round(Math.random()*100));
System.out.println("请输入1~100之间的数");
int min = 1;
int max = 100;
while(true){
Scanner sc = new Scanner(System.in);
int cs = sc.nextInt();
if(cs>num){
max = cs;
System.out.println("猜大了!" + "请输入" + min + "~" + max + "之间的数");
} else if(cs<num){
min = cs;
System.out.println("猜小了!" + "请输入" + min + "~" + max + "之间的数");
} else{
System.out.println("恭喜你!Bingo~");
}
}
}
} |