这段代码工作为什么变量在“;”之后未被识别在Java中
public static void main(String[] args) {
//print from 1-100
for (int i = 0;
i < 100;
i ++)
{
System.out.print(i + "\n ");
}
}
但是这一次没有。
public static void main(String[] args) {
//print from 1-100
for (int i = 0;
i < 100;
i ++); // Why does ; stop i from being recognized?
{
System.out.print(i + "\n ");
}
}
为什么将停止变量;
后i++)
从System.out.print(i + "\n ");
被认可?
这是Java独有的吗?
可能重复的[我不能解析为一个变量,我正在写一个Java程序,它将字符串作为参数反转](http://stackoverflow.com/a/32665527/3841803) – silentprogrammer
将一个分号后你的循环意味着你以后没有身体。这意味着'i'不再在范围中定义。 –
可能重复的[我不能解析为一个变量。我正在写一个Java程序,将字符串作为参数反转](http://stackoverflow.com/questions/32665469/i-cannot-be-resolved-to-a -variable-i-am-writing-a-java-program-which-reverses-a) – Tom