更新時間:2022-11-10 10:55:17 來源:動力節點 瀏覽1132次
命令行參數是在程序執行時在命令行上直接跟在程序名稱后面的信息。在 Java 程序中訪問命令行參數非常容易。它們作為字符串存儲在傳遞給 main() 的字符串數組中。
以下程序顯示調用它的所有命令行參數
public class CommandLine {
public static void main(String args[]) {
for(int i = 0; i<args.length; i++) {
System.out.println("args[" + i + "]: " + args[i]);
}
}
}
嘗試執行此程序,如下所示
$java CommandLine this is a command line 200 -100
輸出
這將產生以下結果
args[0]: this
args[1]: is
args[2]: a
args[3]: command
args[4]: line
args[5]: 200
args[6]: -100
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習