Java Operators
Java Operators - Important Points
1. | What is the result of the expression 6 % 4? |
---|
A. 2
B. 0
C. 1
D. 4
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The % operator gives the remainder after division. In this case, 6 divided by 4 gives a remainder of 2.
2. | What is the result of the expression 3 * 2 + 5 / 2? |
---|
A. 6.5
B. 5.5
C. 7
D. 6
View Answer Discuss Work SpaceAnswer: option c
Explanation:
Multiplication and division have the same level of precedence, so they are evaluated from left to right. Thus, 3 * 2 is evaluated first, resulting in 6. Then, 5 / 2 is evaluated, resulting in 2 (because it's an integer division). Finally, 6 + 2 is evaluated, resulting in 8.
3. | Which of the following is the correct operator for equality testing? |
---|
A. =
B. ==
C. !=
D. >
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The == operator is used for equality testing in Java. The = operator is used for assignment, not comparison.
4. | Which of the following operators is used to increment a variable by 1? |
---|
A. +=
B. ++
C. --
D. *
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The ++ operator is used to increment a variable by 1. For example, i++ is equivalent to i = i + 1.
5. | What is the result of the expression true || false? |
---|
A. 1
B. 0
C. 1
D. 0
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The || operator is the logical OR operator. If either of the operands is true, the result is true.