KnowledgeBoat Logo

Computer Applications

Write valid statements for the following in Java:

i. Print the rounded off value of 234.49

ii. Print the absolute value of -9.99

iii. Print the largest of -45 and -50

iv. Print the smallest of -56 and -57.4

v. Print a random integer between 50 and 70

vi. Print 10.5 raised to the power 3.8

Java Math Lib Methods

70 Likes

Answer

i. Print the rounded off value of 234.49

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));

Answered By

36 Likes


Related Questions