配列に対するループ:問題4
問題:以下のプログラムの実行結果は以下のうちどれか?
A. 実行時に例外「ArrayIndexOutOfBoundsException」が発生する
B. 2345 が出力される
C. 12345 が出力される
D. 何も表示されない
class M {
public static void main(String[] args) {
int[] x = { 1, 2, 3, 4, 5 };
for (int i = 1; i < x.length; i++) {
System.out.print(x[i]);
}
}
}
解答:
C. 12345 が出力される
A. 実行時に例外「ArrayIndexOutOfBoundsException」が発生する
B. 2345 が出力される
C. 12345 が出力される
D. 何も表示されない
class M {
public static void main(String[] args) {
int[] x = { 1, 2, 3, 4, 5 };
for (int i = 1; i < x.length; i++) {
System.out.print(x[i]);
}
}
}
解答:
C. 12345 が出力される
配列に対するループ:問題3
問題:以下のプログラムの実行結果は以下のうちどれか?
A. 実行時に例外「ArrayIndexOutOfBoundsException」が発生する
B. 2345 が出力される
C. 12345 が出力される
D. 何も表示されない
class M {
public static void main(String[] args) {
int[] x = { 1, 2, 3, 4, 5 };
for (int i = 1; i <= x.length; i++) {
System.out.print(x[i]);
}
}
}
解答:
A. 実行時に例外「ArrayIndexOutOfBoundsException」が発生する
A. 実行時に例外「ArrayIndexOutOfBoundsException」が発生する
B. 2345 が出力される
C. 12345 が出力される
D. 何も表示されない
class M {
public static void main(String[] args) {
int[] x = { 1, 2, 3, 4, 5 };
for (int i = 1; i <= x.length; i++) {
System.out.print(x[i]);
}
}
}
解答:
A. 実行時に例外「ArrayIndexOutOfBoundsException」が発生する