如何给猜数字小游戏中加上一个统计输入的次数 并输出import java.util.Scanner;
class Random{
public static void main (String[] agrs){
Scanner sc= new Scanner(System.in);
System.out.println("请输入一个整数,范围0-100");
int guessNum=(int)(Math.random()*100)+1;
while (true) {
int result = sc.nextInt();
if (result>guessNum) {
System.out.println("大");
}else if (result<guessNum) {
System.out.println("小");
}else {
System.out.println("猜对了");
break;}}}}
|
|