हिंदी

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
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 [पृष्ठ ४६]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 1 Revision of Class 9 Syllabus
Exercises | Q 5. (vi) | पृष्ठ ४६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×