Biology, asked by PrincessKritiSanon, 7 months ago

What value is returnedwhen
Math.abs(Math.floor(-29.7)) get
executed?
a. 29.7
b. 29
c. 30.0
d. 30​

Answers

Answered by namrta4
1

Answer:

Hence the Math class java provides these two constants as double fields.

Math.E - having a value as 2.718281828459045

Math.PI - having a value as 3.141592653589793

A) Let us have a look at the table below that shows us the Basic methods and its description

Method Description Arguments

abs Returns the absolute value of the argument Double, float, int, long

round Returns the closed int or long (as per the argument) double or float

ceil Returns the smallest integer that is greater than or equal to the argument Double

floor Returns the largest integer that is less than or equal to the argument Double

min Returns the smallest of the two arguments Double, float, int, long

max Returns the largest of the two arguments Double, float, int, long

Below is the code implementation of the above methods:

Note: There is no need to explicitly import java.lang.Math as its imported implicitly. All its methods are static.

Integer Variable

int i1 = 27;

int i2 = -45;

Double(decimal) variables

double d1 = 84.6;

double d2 = 0.45;

Math.abs

public class Guru99 {

public static void main(String args[]) {

int i1 = 27;

int i2 = -45;

double d1 = 84.6;

double d2 = 0.45;

System.out.println("Absolute value of i1: " + Math.abs(i1));

System.out.println("Absolute value of i2: " + Math.abs(i2));

System.out.println("Absolute value of d1: " + Math.abs(d1));

System.out.println("Absolute value of d2: " + Math.abs(d2));

}

}

Output:

Absolute value of i1: 27

Absolute value of i2: 45

Absolute value of d1: 84.6

Absolute value of d2: 0.45

Math.round

public class Guru99 {

public static void main(String args[]) {

double d1 = 84.6;

double d2 = 0.45;

System.out.println("Round off for d1: " + Math.round(d1));

System.out.println("Round off for d2: " + Math.round(d2));

}

}

Output:

Round off for d1: 85

Round off for d2: 0

Math.ceil & Math.floor

public class Guru99 {

public static void main(String args[]) {

double d1 = 84.6;

double d2 = 0.45;

System.out.println("Ceiling of '" + d1 + "' = " + Math.ceil(d1));

System.out.println("Floor of '" + d1 + "' = " + Math.floor(d1));

System.out.println("Ceiling of '" + d2 + "' = " + Math.ceil(d2));

System.out.println("Floor of '" + d2 + "' = " + Math.floor(d2));

}

}

Output:

Ceiling of '84.6' = 85.0

Floor of '84.6' = 84.0

Ceiling of '0.45' = 1.0

Floor of '0.45' = 0.0

Similar questions