8 Comments

  1. Vlasec

    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.

    Reply
  2. SoldierKB

    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).

    Reply
  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.

    Reply
  4. raja

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

    Reply
  5. Daniel Couillard

    11

    Reply
    • admin

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

      Reply
      • Daniel Couillard

        OH! I like this then >=D

        Thank you for your reply =)

        Reply

Leave a Reply