Question:

Assertion (A): The result of the Java expression \(3 + 7/2\) is \(6\).
Reason (R): According to the hierarchy of operators in Java, addition is done first followed by division.

Show Hint

In Java, always remember two things: \textbf{division has higher precedence than addition}, and \textbf{integer division removes the decimal part}. So \(7/2\) becomes \(3\), not \(3.5\).
  • (A) is true and (R) is false.
  • (A) is false and (R) is true.
  • Both (A) and (R) are true and (R) is the correct explanation of (A).
  • Both (A) and (R) are true, but (R) is not the correct explanation of (A).
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Evaluate the expression \(3 + 7/2\) using Java rules.
In Java, when both operands of division are integers, integer division is performed. This means the decimal part is discarded.
So, \[ 7/2 = 3 \] Now substitute this value into the expression: \[ 3 + 7/2 = 3 + 3 = 6 \] Hence, the Assertion (A) is true.
Step 2: Check the operator precedence in Java.
According to the operator precedence rules in Java, division is performed before addition, not the other way round.
So in the expression \[ 3 + 7/2 \] first \(7/2\) is evaluated, and after that \(3\) is added.
Therefore, the statement given in the Reason that addition is done first followed by division is incorrect.
Step 3: Analyze Assertion and Reason together.
Let us compare both statements carefully:
  • Assertion (A): True, because \(7/2 = 3\) in integer division, and \(3 + 3 = 6\).
  • Reason (R): False, because Java follows precedence where division is done before addition.
So, the Assertion is correct, but the Reason is wrong.
Step 4: Choose the correct option.
The option that correctly matches this situation is:
\[ \text{(A) (A) is true and (R) is false.} \] Final Answer:(A) Assertion is true and Reason is false.
Was this answer helpful?
0
0

Questions Asked in ICSE Class X board exam

View More Questions