Comprog PreFi Reviewer
Comprog PreFi Reviewer
1. Which of the following is NOT a valid Java input method from the
Scanner class?
a) nextInt()
b) nextLine()
c) nextChar()
d) nextDouble()
System.out.print("One");
System.out.println("Two");
System.out.print("Three");
a) OneTwo\nThree
b) One\nTwoThree
c) OneTwoThree
d) One\nTwo\nThree
10. What happens if you put a semicolon immediately after the for
loop parentheses?
a) The loop body is executed once
b) The loop body is executed infinitely
c) The loop body is not executed at all
d) A compile-time error occurs.
11. What is a nested loop?
a) A loop that contains another loop inside its body
b) A loop that never terminates
c) A loop that contains multiple conditions
d) A loop that uses multiple loop variables
10. What does the equals() method return if two strings have the
same characters in the same order?
a) true
b) false
c) 0
d) 1
21. What does the new operator do when used with arrays?
a) Declares a new array variable
b) Allocates memory for the array
c) Initializes the array elements
d) Accesses an element in the array
Essay (5 items):
3. Explain the difference between the break and continue keywords within
a loop structure. Give practical examples.