在java中怎么用if else 与while 制作简单的猜数游戏
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Random r = new Random();
int real = r.nextInt(100);
int guess;
while(true){
System.out.println("请猜数字(0~100的整数):");
guess = sc.nextInt();
if(guess == real){
System.out.println("猜对了!");
break;
}
if(guess>real){
System.out.println("猜大了,继续");
}else {
System.out.println("猜小了,继续");
}
}
}