问题
单项选择题
下面程序的输出结果是 ( )
public class ex2 public static void main(String []args)
for(int cnt=1;cnt<=10;cnt++)
if(cnt<=5)
continue;
System.out.print(cnt+"");
A.1 2 3 4
B.6 7 8 9
C.1 2 3 4 6 7 8 9 10
D.6 7 8 9 10
答案
参考答案:D
解析: 本题考查的是for循环和if语句的混合使用。而if语句后跟的是continue,它的意思是满足if语句,则不执行下一条语句,也不跳出循环,而是继续执行。所以本题中小于等于5的数都没输出,只输出大于5的数,即不满足if语句的数。