版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
package cn.wan;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("game beginning, input the number you guess:");
while (true) {
System.out.println("play again, input the number you guess:");
Random random = new Random(new Date().getTime());
int trueValue = random.nextInt(10);
int guessValue;
while ((guessValue = sc.nextInt()) != trueValue) {
if (guessValue > trueValue) {
System.out.println(guessValue + " is bigger");
} else {
System.out.println(guessValue + " is smaller");
}
}
System.out.println(guessValue + " is right");
}
}
}