package com.example.practice;
import java.util.Random;
import java.util.Scanner;
public class Test10 {
public static void main(String[] args) {
Random random = new Random();
int i = random.nextInt(100);
System.out.println(i);
Scanner scanner = new Scanner(System.in);
int count = 0;
while (true) {
count++;
System.out.println("请输入你要猜的数字:");
int guess = scanner.nextInt();
if (guess > i) {
System.out.println("猜大了");
} else if (guess < i) {
System.out.println("猜小了");
} else {
System.out.println("猜对了,总共猜了"+count+"次");
break;
}
}
}
}
标签:count,guess,数字,int,System,次数,println,输入,out
From: https://www.cnblogs.com/faith007/p/17217707.html