Computer Applications
Answer
Math.rint( ) | Math.round( ) |
---|---|
Rounds off its argument to the nearest mathematical integer and returns its value as a double type. | Rounds off its argument to the nearest mathematical integer and returns its value as an int or long type. If argument is float, return type is int, if argument is double, return type is long. |
At mid-point, it returns the integer that is even | At mid-point, it returns the higher integer. |
double a = Math.rint(1.5); double b =Math.rint(2.5); Both, a and b will have a value of 2.0 | long a = Math.round(1.5); long b = Math.round(2.5); a will have a value of 2 and b will have a value of 3 |
Related Questions
Explain the following function:
Math.log()
Distinguish between Math.ceil() and Math.floor()
Write a program to calculate the value of the given expression:
1/a2 + 2/b2 + 3/c2
Take the values of a, b and c as input from the console. Finally, display the result of the expression to its nearest whole number.For every natural number m>1; 2m, m2-1 and m2+1 form a Pythagorean triplet. Write a program to input the value of 'm' through console to display a 'Pythagorean Triplet'.
Sample Input: 3
Then 2m=6, m2-1=8 and m2+1=10
Thus 6, 8, 10 form a 'Pythagorean Triplet'.