0

I want the following code to count backwards from 33 to 11 but I can't figure out why this does not work. I'm sure that I'm going to have a Homer Simpson "d'oh" moment when I finally learn the answer, but for now, I'd really appreciate any help.

    for(int i = 33; i <= 11; i--)
    {
        System.out.println(i);
    }
1
  • 8
    I think you meant i >= 11 Commented Nov 7, 2011 at 2:58

2 Answers 2

5

The loop will execute only as long as i <= 11. This is not true the very first time, so the loop never executes. Instead, you want the loop to execute as long as i >= 11 -- greater than 11, not less than 11. With that small correction, your loop will be fine.

Sign up to request clarification or add additional context in comments.

1 Comment

I have to wait for a certain period (around 4 min) before it will allow me to accept.
1

It should be:

for(int i = 33; i >= 11; i--)
{
      System.out.println(i);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.