Advertisements
Advertisements
Question
What will be the output of the given Java code after the calculation [note the data types]?
double d = 43, f = 86, g = 0,h = 0;
g = d/f;
h = f/d;
System.out.println ("G=" +g+ "H=" +h);
Sum
Advertisements
Solution
g = d/f;
- This is floating-point division because the variables are of type double `43.0/86.0` = 0.5.
- g gets the exact decimal value of 0.5.
h = f/d;
- This evaluates `86.0/43.0` = 2.
- h gets the exact decimal value of 2.0.
shaalaa.com
Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 45]
