问题 问答题

请完成下列Java程序。程序的功能是利用迭代法求一个数的平方根(求平方根的迭代公式为:Xn+1=1/2(Xn+a/Xn)).
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
public class PingFangGen
public static void main(String args[])
System. out. println(Math, sqrt(2.0));

static double sqrt(______)
double x=1.0
do

_______

while( Math. abs(x*x-a)/a>le-6)
return x;

答案

参考答案:double a
x=(x+a/x);

解析: 本题主要考查do---while循环语句及Java的基本运算。do---while循环又称“直到型”循环,它的一般格式为:[初始化部分]do{循环体部分;迭代部分;}while(判断部分);。说明如下:(1)do---while结构首先执行循环体,然后计算终止条件,若结果为true,则循环执行大括号中的语句或代码块,直到布尔表达式的结果为 false。(2)与while结构不同的是,do---while结构的循环至少被执行一次,这是“直到型”循环的特点。在本题中,double a语句是定义一个 double型变量a,x=(x+a/x);语句的功能是迭代求出被开平方的变量。

阅读理解

阅读理解。

     When Mencius (孟子) was a little boy, his father died. Mencius and his mother were quite poor. One day

Mencius returned home from school and found his mother making some cloth. It was very beautiful and

expensive.

      "How much of the book have you read today?" Mencius' mother asked him. "I haven't read any of it yet."

Mencius replied, "I played with some friends of mine in the fields." 

     When his mother heard this, she picked up a pair of scissors and cut the cloth. 

     "Why have you cut your cloth?" Mencius asked, "It was so beautiful but now you've wasted (浪费) it." "You

have wasted your time," his mother said, "now I have wasted mine. Look at the terrible things we have done."

     Mencius learnt a lot from this lesson. After that, he always studied hard.

1. When did this story happen? [ ]

A. Not long before liberation (解放).

B. More than 2000 years ago.

C. About 400 years ago.

D. In the 18th century.

2. What was Mencius doing while his mother was cutting the cloth? [ ]

A. He was reading his book.

B. He was playing in the fields.

C. He was trying to help her.

D. He was watching strangely.

3. The mother cut the cloth because _______. [ ]

A. she thought making cloth was wasting time

B. she wanted to give her son a lesson

C. she wanted to use more beautiful and expensive cloth

D. she wanted her son to do his lessons at once

4. Mencius and his mother were quite poor because ___________________.

5. When the mother knew Mencius had not read any books, she felt s__________________.

单项选择题