ICSE Class 9 Computer Applications Question 8 of 8

Mathematical Library Methods — Question 8

Back to all questions
8
Question

Question 8

Write the equivalent Java statements for the following, only using the mathematical functions:

i. Print the positive value of -101.

Answer
System.out.println(Math.abs(-101));

ii. Store the value -125 in a variable and print its cube root.

int a = -125;
System.out.println(Math.cbrt(a));

iii. Store the value 89.99 in a variable and convert it into its closest integer that is greater than or equal to 89.99.

double a = 89.99;
System.out.println(Math.round(a));