Computer Applications
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.
- (A) is true and (R) is false.
- (A) is false and (R) is true.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
Answer
(A) is true and (R) is false.
Reason — In the expression 3 + 7/2, division has higher precedence than addition, so 7/2 is evaluated first using integer division, giving 3, and then added to 3 → 3 + 3 = 6, so Assertion (A) is true. However, the Reason (R) is incorrect because it wrongly states that addition is performed before division, which is not true in Java operator precedence.
Related Questions
In the following method prototype to accept a character, an integer and return YES or NO, fill in the blank to complete the method prototype.
public ............... someMethod(char ch, int n)- boolean
- String
- int
- double
In a calculator which Java feature allows multiple methods named calculate() for the different operations?
- abstraction
- inheritance
- encapsulation
- polymorphism
What is the type of parameter to be given for the method parseInt()?
- double
- String
- char
- int
To extract the word NOW from the word "ACKNOWLEDGEMENT", the Java statement
"ACKNOWLEDGEMENT".substring(3, ...............)is used.Choose the correct number to fill in the blank.
- 6
- 7
- 5
- 8