java初學(五)猜數字

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");
        }

    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章