I wrote the following class:
public class TestOne {
public static void main(String[] args) {
int count = 0;
for (int i = 0; i < 100; i++) {
count++;
}
System.out.println(count);
}
}
The output is 100
.
Then I added a semicolon:
public class TestOne {
public static void main(String[] args) {
int count = 0;
for (int i = 0; i < 100; i++); { // <-- Added semicolon
count++;
}
System.out.println(count);
}
}
The output is 1
.
The result is unbelievable. Why does this added semicolon change the meaning of my program so dramatically?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…