接受鍵盤輸入數(shù)據(jù)的步驟:
(1) 創(chuàng)建一個掃描器對象.
(2) 調(diào)用掃描器對象的next(), nextInt()方法掃描數(shù)據(jù)
(3)導(dǎo)入包 import java.util.*;
import java.util.*;
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入一個數(shù)字;);
int score = scanner.nextInt();
System.out.println("輸入的數(shù)字是:"+score);
隨機數(shù):
/*
*? 隨機數(shù)生成:
*? 步驟:
*? 1. 創(chuàng)建一個隨機數(shù)對象。
*? 2. 調(diào)用隨機數(shù)對象的nextInt方法
*? 3. 導(dǎo)包
*
*? import java.util.*;
*
*? Random random = new Random();
int randomNum = random.nextInt(10) + 1;? //1~10
System.out.println( "隨機數(shù)為: "+randomNum );
* */