Discussion
Which line rests on a mistaken assumption?
public class Sample43
{
public static void main(String[] args)
{
assert Math.round(-2.5) == -3 : Math.round(-2.5);
System.out.println(Math.round(-2.5));
}
}
Answer: C
Math.round adds one half and takes the floor, so a value exactly halfway rounds toward positive infinity: -2.5 becomes -2, not -3. The assertion assumes rounding moves away from zero on both sides, which holds for positive halves only.
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