菜鳥寫代碼--猜數字小遊戲--05

import java.util.Scanner;
public class Test {
	public static void main(String[] args) {	
	//程序產生一個隨機數
		int number=(int)(Math.random()*100+1);
		while(true) {
			Scanner sc=new Scanner(System.in);
			System.out.println("請輸入你猜的數據1-100");
			int a=sc.nextInt();
			if(a<number) {
				System.out.println("你猜的小了");
			}else if(a>number) {
				System.out.println("你猜的大了");
			}else {
				System.out.println("恭喜你猜對了");		
				break;
			}				
		}		
	}
}

在這裏插入圖片描述

發佈了24 篇原創文章 · 獲贊 4 · 訪問量 1752
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章