All possible values of int from the smallest to the largest, using Java.

Posted by Totophil on Stack Overflow See other posts from Stack Overflow or by Totophil
Published on 2009-05-07T16:15:25Z Indexed on 2010/05/23 18:50 UTC
Read the original article Hit count: 350

Filed under:
|
|

Write a program to print out all possible values of int data type from the smallest to the largest, using Java.

Some notable solutions as of 8th of May 2009, 10:44 GMT:

1) Daniel Lew was the first to post correctly working code.

2) Kris has provided the simplest solution for the given problem.

3) Tom Hawtin - tackline, came up arguably with the most elegant solution.

4) mmyers pointed out that printing is likely to become a bottleneck and can be improved through buffering.

5) Jay's brute force approach is notable since, besides defying the core point of programming, the resulting source code takes about 128 GB and will blow compiler limits.

As a side note I believe that the answers do demonstrate that it could be a good interview question, as long as the emphasis is not on the ability to remember trivia about the data type overflow and its implications (that can be easily spotted during unit testing), or the way of obtaining MAX and MIN limits (can easily be looked up in the documentation) but rather on the analysis of various ways of dealing with the problem.

© Stack Overflow or respective owner

Related posts about java

Related posts about interview-questions