1Z0-811 1Z0-811 Java Operators and Control Flow 1 — Questions and Answers
Question 1: What is the result of the expression `10 % 3` in Java?
- 3
- 1 (Correct answer)
- 0
- 3.33
Correct answer: 1
The `%` operator returns the remainder of integer division, so 10 divided by 3 leaves a remainder of 1.
Question 2: Which operator is used for short-circuit logical AND in Java?
- &
- && (Correct answer)
- AND
- |
Correct answer: &&
The `&&` operator performs a short-circuit logical AND, meaning the second operand is not evaluated if the first is false.
Question 3: What is the output of `int x = 5; System.out.println(x++);`?
- 6
- 5 (Correct answer)
- 4
- Compilation error
Correct answer: 5
The post-increment operator `x++` returns the current value of x (5) before incrementing it to 6.
Question 4: Which control flow statement is used to exit the current iteration of a loop and proceed to the next?
- break
- return
- continue (Correct answer)
- exit
Correct answer: continue
The `continue` statement skips the rest of the current loop iteration and jumps to the loop condition check for the next iteration.
Question 5: What is the result of `true || false && false` in Java?
- false
- true (Correct answer)
- Compilation error
- null
Correct answer: true
Due to operator precedence, `&&` is evaluated before `||`, so the expression becomes `true || (false && false)` = `true || false` = `true`.
Question 6: Which of the following is the ternary operator syntax in Java?
- condition ? valueIfFalse : valueIfTrue
- condition ? valueIfTrue : valueIfFalse (Correct answer)
- if(condition) valueIfTrue else valueIfFalse
- condition :: valueIfTrue ? valueIfFalse
Correct answer: condition ? valueIfTrue : valueIfFalse
The ternary operator syntax is `condition ? valueIfTrue : valueIfFalse`, returning the first value when condition is true.
What is the result of the expression `10 % 3` in Java?