import java.util.*;
class Demo5
{
public static void main(String[] args)
{
/*
* A:案例演示(人猜电脑)
* 需求:猜数字小游戏(数据在1-100之间)
int sjs = (int)(Math.random()*100)+1;
Scanner sc = new Scanner(System.in);
System.out.println("请输入要1-100之间的整数:");
int max = 100;
int min = 0;
while(true){
int a = sc.nextInt();
if(a==sjs){
System.out.println("恭喜你,猜对了");
break;
}else if(a<sjs){
min = a;
System.out.println("小了,请输入"+min+"到"+max+"之间的数");
}else if(a>sjs){
max = a;
System.out.println("大了,请输入"+min+"到"+max+"之间的数");
}
}
}
}
|
|