ICSE Class 9 Computer Applications Question 4 of 16

Mathematical Library Methods — Question 4

Back to all questions
4
Question

Question 4

Write valid statements for the following in Java:

i. Print the rounded off value of 234.49

Answer
System.out.println(Math.round(234.49));

ii. Print the absolute value of -9.99

System.out.println(Math.abs(-9.99));

iii. Print the largest of -45 and -50

System.out.println(Math.max(-45, -50));

iv. Print the smallest of -56 and -57.4

System.out.println(Math.min(-56, -57.4));

v. Print a random integer between 50 and 70

int range = 70 - 50 + 1;
int num = (int)(range * Math.random() + 50);
System.out.println(num);

vi. Print 10.5 raised to the power 3.8

System.out.println(Math.pow(10.5, 3.8));