Java 標準類使用 Java.util.Scanner

Java.util.Scanner
import java.util.Scanner;

public class HelloWorld {
	
	public static void main(String[] args){

		Scanner scanner = new Scanner(System.in);
		
		int number = (int) (Math.random() * 10);
		int guess;

		do {
			
			System.out.println("guess 1 ~ 9");
			guess = scanner.nextInt();
			
			/* 從入力流取得內容
			 * nextByte()
			 * nextShort()
			 * nextLong()
			 * nextFloat()
			 * nextDouble()
			 * nextBoolean()
			 * next()
			 * nextLine()
			 * 
			 * */
		
		} while(guess != number);
		
		System.out.println("OK!");	
	}
}

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