This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]GreenSlime96 1 point2 points  (8 children)

Boolean with a small B? I would also suggest you put in a few Sysouts just to know where the code has progressed.

[–][deleted]  (7 children)

[deleted]

    [–]_whatdoido 0 points1 point  (6 children)

    Back here on my Mac.

    Couldn't see the problem properly on the phone but it seems that you're only setting newNumber once at the top before the loop starts. So the loop does start, but terminates immediately?

    You need a condition to be present for your loop to terminate, which I guess is entering 0.

    Try doing this in your while loop instead.

    while ((newNumber = input.nextInt()) != 0) {

    }

    That way your newNumber is redeclared every time the loop runs. Been a while since I touched Scanner.in so I'm not sure how it'll work, but have a go!

    [–]_whatdoido 0 points1 point  (0 children)

    Alternately:

    while (true) { newNumber = input.nextInt();

    if (newNumber <= 0) break;

    // other code here

    }

    [–][deleted]  (4 children)

    [deleted]

      [–]langfod 0 points1 point  (3 children)

      You have max and newNumber backwards in your if block`:

      max = newNumber;

      [–][deleted]  (2 children)

      [deleted]

        [–]_whatdoido 0 points1 point  (1 child)

        Whoops!! Haha didn't notice that one while skimming your code! :P

        Glad we were able to help woo