java错误i cannot be resolved求解这段代码出错:int sum = 0;for(int i = 0; i < 10; ++i){if(i == 5)break;if(i > 3)continue;sum += i;}System.out.println(i+sum);//这里显示i cannot be resolved 错误看懂了.

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 14:16:01
java错误icannotberesolved求解这段代码出错:intsum=0;for(inti=0;i3)continue;sum+=i;}System.out.println(i+sum);//

java错误i cannot be resolved求解这段代码出错:int sum = 0;for(int i = 0; i < 10; ++i){if(i == 5)break;if(i > 3)continue;sum += i;}System.out.println(i+sum);//这里显示i cannot be resolved 错误看懂了.
java错误i cannot be resolved
求解这段代码出错:
int sum = 0;
for(int i = 0; i < 10; ++i)
{
if(i == 5)
break;
if(i > 3)
continue;
sum += i;
}
System.out.println(i+sum);//这里显示i cannot be resolved 错误
看懂了.

java错误i cannot be resolved求解这段代码出错:int sum = 0;for(int i = 0; i < 10; ++i){if(i == 5)break;if(i > 3)continue;sum += i;}System.out.println(i+sum);//这里显示i cannot be resolved 错误看懂了.
System.out.println(i+sum);这里的i是不能使用的,因为这个i是循环里定义的私有变量
如果想实现你的需求,你就要将i定义在外面如:
int sum=0;
int i=0;