English

What will be the output of the given Java code after the calculation [note the data types]? int m = 62, k = 10,r = 0, q = 0; r = m/k; q = k/m; System.out.println ("R=" +r+ “Q=" +q);

Advertisements
Advertisements

Question

What will be the output of the given Java code after the calculation [note the data types]?

int m = 62, k = 10,r = 0, q = 0; 

r = m/k;

q = k/m;

System.out.println ("R=" +r+ “Q=" +q);

Sum
Advertisements

Solution

r = m/k;

  • This is integer division because both variables are int `62/10` = 6.2.
  • r gets the value 6.

q = k/m;

  • This evaluates `10/62` = 0.1612..
  • Java truncates the decimal portion completely, leaving 0.
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 5. (i) | Page 45
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×