Java Quiz 10

What will be output of this simple java program ?

 

Java Quiz
 

 

Click below to start the quiz :

© 2015 – 2016, https:. All rights reserved. On republishing this post, you must provide link to original post

8 comments

  1. There is no real difference between Integer and int in this behavior. Neither will give you a greater number than Integer.MAX_VALUE. Adding 1 to max int causes overflow, resulting in Integer.MIN_VALUE. The cycle can never end, because there is no Integer greater than Integer.MAX_VALUE.

  2. The explanation is not really correct. The thing is in the loop – in case condition is i < end we’ll get answer 10. But we have i <= end, so when i = Integer.MAX_VALUE condition i <= end will still be true, and in the next step i will be incremented by one resulting in Integer.MIN_VALUE (because of int overflow).

  3. Swapnil Chaudhari

    Your answer is wrong. Integer will be unboxed to int. hence the answer should be 10 and if you say Integer is not same as int, the compile time error will occur.

  4. It should be 0. B’coz condition fails in for loop. so  count variable wont increment.

  5. Daniel Couillard

    11

    1. Nope.. that’s not correct.. its an overflow situation .. click Start quiz button in the quiz to see correct answer

      1. Daniel Couillard

        OH! I like this then >=D

        Thank you for your reply =)

Leave a Reply.. code can be added in <code> </code> tags

%d bloggers like this: