Unit 4: Iteration

Showing 20 of 25 questions

Q1
MULTIPLE_CHOICEEasy

What is the output of the following code?

Q2
MULTIPLE_CHOICEMedium

How many times does "*" get printed?

Q3
MULTIPLE_CHOICEHard

What is the output of the following code?

Q4
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q5
MULTIPLE_CHOICEHard

What is the value of x after the following code executes?

Q6
MULTIPLE_CHOICEHard

What is the output of the following code?

Q7
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q8
MULTIPLE_CHOICEEasy

How many times is "Hi" printed?

Q9
MULTIPLE_CHOICEHard

What is the output of the following code?

Q10
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q11
MULTIPLE_CHOICEEasy

What is the output?\nfor (int i = 0; i < 5; i++) System.out.print(i + " ");

Q12
MULTIPLE_CHOICEMedium

How many times does the loop execute?\nint x = 10;\nwhile (x > 0) { x -= 3; }

Q13
MULTIPLE_CHOICEHard

How many times is "*" printed?\nfor (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) System.out.print("*");

Q14
MULTIPLE_CHOICEMedium

Which loop correctly iterates through all elements of int[] arr?

Q15
MULTIPLE_CHOICEMedium

To iterate through each character of a String str, which loop header is correct?

Q16
MULTIPLE_CHOICEEasy

Which of the following creates an infinite loop?

Q17
MULTIPLE_CHOICEMedium

What is the value of sum after this code?\nint sum = 0;\nfor (int i = 1; i <= 5; i++) sum += i;

Q18
MULTIPLE_CHOICEEasy

How many times does this loop execute?\nint x = 100;\nwhile (x < 10) { x++; }

Q19
MULTIPLE_CHOICEMedium

What does this code output?\nString s = "Java";\nString result = "";\nfor (int i = s.length() - 1; i >= 0; i--) result += s.charAt(i);\nSystem.out.println(result);

Q20
MULTIPLE_CHOICEHard

What does this code produce?\nString s = "Hello World";\nint count = 0;\nfor (int i = 0; i < s.length(); i++) if (s.charAt(i) == 'l') count++;\nSystem.out.println(count);

Advertisement