Scanner
を正常に実行したのに、Integer.parseInt(args[0])
を使用したときにエラーが発生しました。スキャナの代わりにInteger.parseInt(args [0])を使用できない
Scanner sc = new Scanner(System.in);
try {
int row = sc.nextInt();
System.out.println("please enter col ");
int col = sc.nextInt();
sc.close();
for (int i = 1;i<= row; i++) {
for (int j = 1; j <= col; j++) {
System.out.print("B");
}
System.out.println();
}
} catch(NumberFormatException e) {
e.printStackTrace();
}
System.out.println();
Integer.parseInt()
を使用するとエラーが発生します。私はInteger.parseInt(args[0])
も整数に変換することを理解していません。
try{
for (int i = 1;i<= Integer.parseInt(args[0]); i++) {
for (int j = 1; j <= Integer.parseInt(args[1]; j++) {
System.out.print("B");
}
System.out.println();
}
} catch(NumberFormatException e) {
e.printStackTrace();
}
System.out.println();
これらのコードスニペットは根本的に異なることをしています。あなたはリンゴとオレンジを比較しています。 –
このコードはどんなエラーを投げますか? –
スキャナは 'System.in'を読み込みますが、' args [0] 'はそうではありません(あなたのプログラムの最初の実行時引数です)。 – dasblinkenlight