1. Write a program to calculate the value of the given expression.
1
3
+
2
12
+
Take the values of a, b and c as input from the console. Finally, display the
the expression to its nearest whole number.
2+1 form a Pythagorean trip
Answers
Answer:
Math.floor method returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer. As -5.0 is the largest mathematical integer less than -4.7 so it is the output. Note that -4.7 is a negative number so the largest integer less than -4.7 is -5.0 and not -4.0.
Question 2
System.out.println(Math.rint(-9.4)+Math.sqrt(9.0));
Output
-6.0
Explanation
Math.rint(-9.4) will give -9.0 as it is nearest integer to -9.4. Math.sqrt(9.0) will give 3.0. So, output will be -9.0 + 3.0 = -6.0
Question 3
System.out.println(Math.max(Math.ceil(14.55),15.5));
Output
15.5
Explanation
Math.ceil(14.55) gives 15.0 as it is the smallest whole number greater than 14.55. After that Math.Max() becomes Math.max(15.0, 15.5). As 15.5 is greater than 15.0, it is the output.
Question 4
System.out.println(Math.sqrt(Math.min(42.5,42.25)));
Output
6.5
Explanation
Math.min(42.5,42.25) gives 42.25. Math.sqrt(42.25) gives output as 6.5.
Question 5
System.out.println(Math.ceil(3.4)+Math.pow(2,3));
Output
12.0