這段代碼工作爲什麼變量在「;」之後未被識別在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