English

Evaluate the following expression as per Java priority and associativity. 1234 % 100 – 1234/100

Advertisements
Advertisements

Question

Evaluate the following expression as per Java priority & associativity.

1234 % 100 – 1234/100

Evaluate
Advertisements

Solution

Priority (Precedence): Modulo (%) and division (/) have higher precedence than subtraction (–), so they are evaluated first.

Associativity: Since % and / share equal precedence, they evaluate from left to right.

  • 1234 % 100: Leaves a remainder of 34.
  • 1234 / 100: Performs integer division, discarding the remainder, which gives 12.
  • 34 – 12: Subtraction completes, giving a final answer of 22.
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. (vi) | Page 45
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×