概要
Javaで「コマンドライン引数の数を確認」の動作を確認してみました。
以下のページを参考にしました。
実装
以下のファイルを作成しました。
JSample2_1.java
class JSample2_1{
public static void main(String args[]){
if (args.length != 2){
System.out.println("引数を2つ指定して下さい");
System.out.println("JSample2_1 値1 値2");
System.exit(1);
}
System.out.println("「" + args[0] + "」");
System.out.println("「" + args[1] + "」");
}
}
以下のコマンドを実行しました。
$ javac JSample2_1.java
$ java JSample2_1 値1 値2
「値1」
「値2」
まとめ
何かの役に立てばと。