Previous | Home | Next |
Control Statements
Answer: There are mainly three programming constructors
- Sequential
- Selection: if and switch statements
- Iteration: for loop, while loop and do-while loop
class conditional { public static void main(String args[]) { int i = 20; int j = 55; int z = 0; z = i < j ? i : j; // ternary operator System.out.println("The value assigned is " + z); } }
Answer: The value assigned is 20
(a). True
(b). False
Answer: (b). False
(a). True
(b). False
Answer: (a). True
(a). True
(b). False
Answer: (b). False
Q.6 The do-while loop repeats a set of code at least once before the condition is tested.
(a). True
(b). False
Answer: (a). True
Answer: The break keyword halts the execution of the current loop and forces control out of the loop. The continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration.
Q.8 The for loop repeats a set of statements a certain number of times until a condition is matched.
(a). True
(b). False
Answer: (a). True
Answer: Yes.
Answer: A while statement checks at the beginning of a loop to see whether the next loop iteration should occur.
A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.
Previous | Home | Next |