200+ câu trắc nghiệm Lập trình Java cơ sở có đáp án - Phần 4

Chương trình ra kết quả là bao nhiêu?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;

29/30

Chương trình ra kết quả là bao nhiêu?

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”); } }

</>

12 not in the array

Found 12 at index 4

Chương trình lỗi

Found it

Giải thích

Chọn đáp án B