What will be output of this simple java program ?
Click below to start the quiz :
© 2015 – 2016, https:. All rights reserved. On republishing this post, you must provide link to original post
0 of 1 questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
0 of 1 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Integers are not same as int. This is an overflow scenario.. the loop is broken
Integers are not same as int. This is an overflow scenario.. the loop is broken
© 2015 – 2016, https:. All rights reserved. On republishing this post, you must provide link to original post
#
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.
#
#
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).
#
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.
#
It should be 0. B’coz condition fails in for loop. so count variable wont increment.
#
11
#
Nope.. that’s not correct.. its an overflow situation .. click Start quiz button in the quiz to see correct answer
#
OH! I like this then >=D
Thank you for your reply =)