1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import org.w3c.dom.ranges.Range; import java.util.Random; import java.util.Scanner;
public class Demo01 { public static void main(String[] args) { Random r = new Random(); int number = r.nextInt(100) + 1; Scanner sc = new Scanner(System.in); while (true){ System.out.print("输入你想要输入的数字:"); int guessNumber = sc.nextInt(); if (guessNumber > number){ System.out.println("大了"); }else if(guessNumber < number){ System.out.println("小了"); }else{ System.out.println("猜中了"); break; } } } }
|