English

What will be the output of the given Java code after the calculation [note the data types]? double ph = Math.ceil(23.7*2) + Math.floor(32.4/2); System.out.println("PH=" +ph);

Advertisements
Advertisements

Question

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

double ph = Math.ceil(23.7*2) + Math.floor(32.4/2); 

System.out.println("PH=" +ph);

Sum
Advertisements

Solution

Evaluate 23.7*2:

23.7 × 2

= 47.4

Math.ceil(47.4):

= 48.0 (rounds up to the next whole number)

= `32.4 / 2`

= 16.2

Math.floor(16.2);

= 16.0 (rounds down to the previous whole number)

= 48.0 + 16.0 

= 64.0

The value 64.0 is stored in the double variable PH.

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. (vii) | Page 46
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×