Computer Science, asked by uttu3381, 8 months ago

What will be the output of the following code?double b = -15.6; double a = Math.rint(Math.abs(b)); System.out.println("a =" + a);

Answers

Answered by itssudhanshukumar
26

Your answer is :16.0

Given: b=-15.6

Math.abs(b)=15.6

Math.rint(Math.abs(b))=Math.rint(15.6)=16.0

The use of Math.abs is to return the absolute value(i.e positive value )

and the use of Math.rint is to return the next integer if the fraction part is >0.5and returns the same integer if the fraction part is <=0.5

Answered by rishikumar418
13

Explanation:

Your answer is :16.0

Given: b=-15.6

Math.abs(b)=15.6

Math.rint(Math.abs(b))=Math.rint(15.6)=16.0

The use of Math.abs is to return the absolute value(i.e positive value )

and the use of Math.rint is to return the next integer if the fraction part is >0.5and returns the same integer if the fraction part is <=0.5

Similar questions