问题 单项选择题

有如下程序 public class Sun { public static void main(String args[ ]) { int x=0; int n=0; while(x<50) { x=(x+2)*(x+3); n=n+1; } System.out.println(n+"和"+x); } } 上述程序的运行结果是( )。

A.1和0

B.2和72

C.3和50

D.4和168

答案

参考答案:B

解析: 本题考查对while循环语句的理解。本例中使用while语句宋计算结果x,第1次循环,x=6,n=1;第2次循环,x=72,n=2。故本题答案是B。

材料分析题
选择题