Unit 4: Iteration
Showing 25 of 25 questions
What is the output of the following code?
How many times does "*" get printed?
What is the output of the following code?
What is the output of the following code?
What is the value of x after the following code executes?
What is the output of the following code?
What is the output of the following code?
How many times is "Hi" printed?
What is the output of the following code?
What is the output of the following code?
What is the output?\nfor (int i = 0; i < 5; i++) System.out.print(i + " ");
How many times does the loop execute?\nint x = 10;\nwhile (x > 0) { x -= 3; }
How many times is "*" printed?\nfor (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) System.out.print("*");
Which loop correctly iterates through all elements of int[] arr?
To iterate through each character of a String str, which loop header is correct?
Which of the following creates an infinite loop?
What is the value of sum after this code?\nint sum = 0;\nfor (int i = 1; i <= 5; i++) sum += i;
How many times does this loop execute?\nint x = 100;\nwhile (x < 10) { x++; }
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);
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);
What does the break statement do in a loop?
What is the output of the following code segment? \nint count = 0;\nfor (int i = 1; i <= 100; i++) { if (i % 3 == 0 && i % 5 == 0) { count++; } }\nSystem.out.println(count);
Consider the following code segment. \nint x = 1;\nint y = 0;\nwhile (x < 20) { if (x % 3 != 0) { y += x; } x += 2; }\nSystem.out.println(y);
What is the output? int sum = 0; for (int i = 1; i <= 100; i++) { if (i % 3 == 0 && i % 5 == 0) sum += i; } System.out.println(sum);
What is the output? int n = 1234; String result = ""; while (n > 0) { result = (n % 10) + result; n /= 10; } System.out.println(result);
Advertisement