Advertisements
Advertisements
प्रश्न
What will be the output of the given Java code after the calculation [note the data types]?
double mh = Math.sqrt (Math.max (6+3*10, 30−2*5+5));
System.out.println ("MH=" + mh);
बेरीज
Advertisements
उत्तर
(6+3*10):
Multiplication (*) has higher precedence: 3 × 10 = 30.
Addition complete: 6 + 30 = 36.
(30−2*5+5):
Multiplication (*) has higher precedence: 2 × 5 = 10.
Subtraction and addition are evaluated left-to-right: 30 − 10 = 20, then 20 + 5 = 25.
Math.max(36, 25):
This compares 36 and 25 and returns the larger value, which is 36.0 (promoted to a double).
Math.sqrt(36.0):
The square root of 36.0 is calculated.
Math.sqrt() always returns a double, which gives MH = 6.0.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1: Revision of Class 9 Syllabus - Exercises [पृष्ठ ४६]
