Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

The following code would not print a table of squares of the integers from 1 to 100.?

The following code would not print a table of squares of the integers from 1 to 100.

What would it print?

for (int i = 1; i < 100; i++);

System.out.println(i + " " + i * i);

3 Answers

Relevance
  • jimbot
    Lv 6
    1 decade ago
    Favorite Answer

    Assuming that i is defined outside the scope of the for loop, it would display 100 and the square of 100.

    The loop doesn't contain any code, it's just a loop that does nothing (other than increase the value of i).

  • CatNip
    Lv 6
    1 decade ago

    100 10000

  • 1 decade ago

    What you are doing is what is called an 'Empty Statement'. This is caused by placing a semi-colon ';' right after the for statement line:

    for (int i = 1; i < 100; i++); < --- See it?

    You need to remove that! Now it should work just fine.

    While it is a simple thing, dont bother beating yourself up over it. It happens to the best of us! :)

    Source(s): Personal Knowledge
Still have questions? Get your answers by asking now.