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);
- jimbotLv 61 decade agoFavorite 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).
- CatNipLv 61 decade ago
- 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