Exercises · Q5
Q.Predict the output of the following code and explain why:
int a = 17, b = 5;
System.out.println(a / b);
System.out.println(a % b);
System.out.println((double) a / b);
int a = 17, b = 5;
System.out.println(a / b);
System.out.println(a % b);
System.out.println((double) a / b);
ChseodishaTextbookSubjectiveImportance★★★★★est
38% · 5/13 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Let us take each statement in turn, with a = 17 and b = 5.
a / b → 3. When both operands are integers, Java performs integer division and discards the fractional part. 17 ÷ 5 is 3.4, but the .4 is dropped, leaving 3.
a % b → 2. The modulus operator % returns the remainder of the division. 17 = 5 × 3 + 2, so the remainder is 2. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.