执行以下循环多少次?
for (int i=2; i <=14; i+=3) {
//body of loop
}
答案 0 :(得分:1)
i
将依次采用以下值(假设循环体不改变它):2,5,8,11,14,最后是17(此时,相反,执行身体,循环终止),这使得身体的5次执行。
for (int i=2; i <=14; i+=3) {
//body of loop
document.write(i);
}
答案 1 :(得分:0)
5
int count = 0;
for (int i = 2; i <= 14; i += 3) {
count++;
}
System.out.println("Num times: " + count);
可生产
Num times: 5