6.What are the final values stored in variables x and y below?
double a=-6.35;
double b=14.74;
double x= Math.abs(Math.ceil(a));
double y=Math.rint(Math.max(a,b));
------------------------------------------------
please show work
Answers
Answered by
2
Answer:
x = Maths.abs(-7.0)
= 7.0
y = Math.rint(14.75)
= 14.0
I think so....
anindyaadhikari13:
Correct.
Answered by
12
Required Answer:-
Question:
- Find the output of the following.
Output:
x = 6.0
y = 15.0
Explanation:
Given snippet,
double a = -6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a,b));
Here,
➡ Math.ceil(a) = Math.ceil(-6.35) = -6.0
Therefore,
➡ Math.abs(-6.0) = 6.0 — (i)
- Math.ceil():- This function returns the higher integer for the given argument.
- As we know that, -6.0 > -6.35 (6.0 is on the right side of -6.35 in number line), so higher integer for this argument is -6.0
- So, Math.ceil(-6.35) returns -6.0
- Math.abs():- This function finds the absolute value of the number. Absolute value means the magnitude of number without it's sign.
- For example, Math.abs(-6) = 6, Math.abs(0) = 0, Math.abs(2) = 2.
★ So, the value of x is 6.0
Now,
➡ Math.max(a, b) = Math.max(-6.35, 14.74) = 14.74
Therefore,
Math.rint(14.74) = 15.0 — (ii)
- Note that Math.max(x, y) finds the highest value among two numbers.
- Here, 14.74 > -6.35. Therefore, Math.max() returned 14.74.
- Math.rint():- This function returns the nearest integer for the argument.
- For positive numbers, if the fractional part is between 0.0 and 0.5, then it returns the integer part for the number or else, it returns the next higher integer.
- For negative numbers, if the fractional part is between 0.0 and 0.5, then the function returns the integer part or else, it returns the lower integer.
- Here, fractional part of 14.74 is 0.74. It is not between 0.0 and 0.5, So the next number is returned i.e., 15.0. So, the output is 15.0
★ So, the value of y is 15.0.
Similar questions