Discussion
Which statement is true given the following?
Double d = Math.random();
Answer: B
Correct answer: 0.0 <= d < 1.0
Math.random() returns a double in the half-open interval from zero inclusive to one exclusive, and the assignment to a Double compiles because autoboxing converts the primitive to its wrapper. Zero is therefore a possible value and one is not - which matters whenever the result is scaled, since (int)(Math.random()*6)+1 gives 1 to 6 precisely because the upper bound is never reached.
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