Discussion
What will be the output of the program?
public class Example19
{
void run()
{
double value = -1.5;
System.out.println(Math.floor(value) + " " + Math.ceil(value));
}
public static void main(String[] args)
{
new Example19().run();
}
}
Answer: C
floor moves toward negative infinity and ceil toward positive infinity, so -1.5 becomes -2.0 and -1.0 respectively. Both return a double, which is why the output carries the decimal point. Thinking of them as round-down and round-up in magnitude reverses the answer for negatives.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development