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

Chương trình sau ra kết quả là gì? class ContinueDemo { public static void main(String[] args) { String searchMe = “peter piper picked a peck of pickled pepers”; int max = searchMe.length();

41/50

Chương trình sau ra kết quả là gì?
class ContinueDemo {
public static void main(String[] args) {
String searchMe = “peter piper picked a peck of pickled pepers”;
int max = searchMe.length();
int numPs = 0;
for (int i = 0; i < max; i++) {
if (searchMe.charAt(i) != 'p') continue;
numPs++;
}
System.out.println(“Found“ + numPs + “p 's in the string.”);
}
}

Found 9 p's in the string.

Found 8 p's in the string.

Found 10 p's in the string.

Không có đáp án đúng.

Giải thích

Chọn đáp án B