A-A+

有如下程序 public class Sun { public static void ma

2022-08-05 20:05:30 问答库 阅读 171 次

问题详情

有如下程序 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。

考点:程序