English

What will be the output of the given Java code after the calculation [note the data types]? double kv = Math.abs(Math.min(Math.floor(9.9), Math.ceil(9.9))−Math.round(24.6)); System.out.println

Advertisements
Advertisements

Question

What will be the output of the given Java code after the calculation [note the data types]?

double kv = Math.abs(Math.min(Math.floor(9.9), Math.ceil(9.9))−Math.round(24.6)); 

System.out.println ("KV=“ +kv);

Sum
Advertisements

Solution

Math.floor(9.9): Rounds downward to the nearest mathematical integer, resulting in 9.0.

Math.ceil(9.9): Rounds upward to the nearest mathematical integer, resulting in 10.0.

Math.min(9.0, 10.0): Compares the two values and returns the smaller one, which is 9.0.

Math.round(24.6): Rounds to the closest integer value, which results in 25 (returned as a long).

(9.0 − 25): The long value 25 is implicitly promoted to a double (25.0) for the subtraction. Thus, 9.0 − 25.0 evaluates to −16.0.

Math.abs(−16.0): Returns the absolute (positive) value of the argument, which is 16.0. This final result is stored in the double variable kv.

shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Revision of Class 9 Syllabus - Exercises [Page 46]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 1 Revision of Class 9 Syllabus
Exercises | Q 5. (x) | Page 46
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×