猜數字

import java.util.Scanner;

public class CaiShu {
	public static void main(String[] args) {
		//設置1到100隨機數
		int num = (int)(Math.random() * 100 + 1); 
		
		while(true){
			Scanner scanner = new Scanner(System.in);
			int i = scanner.nextInt();
			if (i > num){
				System.out.println("大了");
			}
			else if(i < num){
				System.out.println("小了");
			}
			else if(i == num){
				System.out.println("正確");
				break; //結束
			}
		}
	}
}

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