Advertisements
Advertisements
Question
Evaluate the following expression as per Java priority & associativity.
35 % 6 * 7 / 5
Evaluate
Advertisements
Solution
Priority (Precedence): Modulo (%), multiplication (*), and division (/) all have the same precedence level in Java.
Associativity: Because their precedence is equal, Java evaluates them from left to right.
- 35 % 6: Evaluates first. 35 divided by 6 leaves a remainder of 5.
- 5 * 7: Multiplies the result by 7, giving 35.
- 35 / 5: Divides the result by 5. Since all operands are integers, Java performs integer division, giving a final answer of 7.
shaalaa.com
Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 45]
