English

Evaluate the following expression as per Java priority and associativity. 79 % 2 + 2 % 79

Advertisements
Advertisements

Question

Evaluate the following expression as per Java priority & associativity.

79 % 2 + 2 %  79

Evaluate
Advertisements

Solution

Priority (Precedence): Modulo (%) has higher precedence than addition (+), so both modulo operations are evaluated first.

Associativity: Since the two modulo operators share equal precedence, they evaluate from left to right.

  • 79 % 2: Leaves a remainder of 1 (since 2 × 39 = 78).
  • 2 %
  • 79: Since 2 is smaller than 79, it cannot be divided, leaving the entire number as the remainder, 2.
  • 1 + 2: Addition completes, giving a final answer of 3.
shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 45]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 1 Revision of Class 9 Syllabus
Exercises | Q 4. (v) | Page 45
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×