Advertisements
Advertisements
प्रश्न
What will be the output of the given Java code after the calculation [note the data types]?
int b = 300, a = 150 ; double w = 0,p = 0;
w = b/a;
p = a/b;
System.out.println ("W=" +w+ "P=" +p);
बेरीज
Advertisements
उत्तर
w = b/a;
- b and a are both integers (int), so Java performs integer division first: `300/150` = 2.
- The result (2) is then assigned to the double variable w, converting it to 2.0.
p = a/b;
- Both are integers `150/300` = 0.5.
- The integer result (0) is assigned to the double variable p, converting it to 0.0.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1: Revision of Class 9 Syllabus - Exercises [पृष्ठ ४६]
