未分类题

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

A.out.println(n+'和'+x);
B.1和0
B.2和72
C.3和50
D.4和168


【参考答案】

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

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

问答题
单项选择题