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

你可能感兴趣的:(Java,Memo)