执行下列程序段后输出的结果是______。 public class Test{ public static void main(String args[]){ int x,y; for(y=1,x=1;y<=50;y++){ if(x>=10)break

admin2012-12-13  30

问题 执行下列程序段后输出的结果是______。
public class Test{
public static void main(String args[]){
int x,y;
for(y=1,x=1;y<=50;y++){
if(x>=10)break;
if  (x%2==1){
x+=5;
continue;
}
x-=2;
}
System.out.println(y);
}
}

选项

答案6

解析 本题是对for循环和if条件语句的综合考查。当y=1,x=1时不满足第1个 if语句,向下继续执行第2个if语句x=6,继续执行 for循环;当y=2,x=6时,不满足第1个和第2个 if语句,x=3,继续执行for循环;当y=3,x=3时,不满足第1个if语句,向下继续执行第2个if语句 x=8,继续执行for循环;一直执行下去,直到y=6, x=12时满足第1个if语句,退出for循环。
转载请注明原文地址:https://kaotiyun.com/show/e22p777K
0

最新回复(0)