import java.util.Scanner;
public class Game {
private Game(){};
public static void pleyGame(){
Scanner sc = new Scanner(System.in);
//获取一个1到100的随机数
int num = (int)(Math.random()*100)+1;
while(true){
System.out.println("请输入你要猜的数1-100");
int i = sc.nextInt();
if(i<0||i>100){
System.out.println("你猜的数不合法,请输入1-100的数");
}
else if (i == num) {
System.out.println("恭喜你猜对了,可惜没有奖励!");
break;
} else if(i>num){
System.out.println("你猜的数大了");
}else {
System.out.println("你猜的数小了");
}
}
}
}
|
|