300 Câu hỏi trắc nghiệm lập trình Java có đáp án - Phần 3

Chương trình trên sai ở dòng nào? class BreakDemo { public static void main(String[] args) { int[] arrayOfInts = { 32, 87, 3, 589, 12, 1076, 2000, 8, 622, 127 }; int searchFor = 12; int i; bo

38/50

Chương trình trên sai ở dòng nào?
class BreakDemo {
public static void main(String[] args) {
int[] arrayOfInts = {
32,
87,
3,
589,
12,
1076,
2000,
8,
622,
127
};
int searchFor = 12;
int i;
boolean fountIt = false;
for (i = 0; i < arrayOfInts.length; i++) {
if (arrayOfInts[i] == searchFor) {
fountIt = true;
break;
}
}
if (fountIt) {
System.out.println(“Found“ + searchFor + “at index“ + i);
} else System.out.println(searchFor + “not in the array”);
}
}

2 và 6

3 và 11, 15

5, 7, 9

Chương trình không sai

Giải thích

Chọn đáp án D