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?
