问题 单项选择题

下面程序段的输出结果是( )。
public class Test
public static void main (String[] args)
int n=10,result=0;
for (int i=1;i<=n;i++) result+=i;
System.out.println("result is"+result);

A) result is 55
B) result is 45
C) result is 56
D) result is 54

答案

参考答案:A

解析: for循环执行时,首先执行初始化操作,然后判断终止条件是否满足,如果满足,则执行循环体中语句,最后执行迭代部分。完成一次循环后,重新判断终止条件。题目中求1到10的和,主要注意终止条件是i<=n,因此包括10在内,所以结果为55,选择A。

阅读理解

阅读理解。

     Once upon a time, there were three tortoises who were friends. One of them was a large tortoise (乌龟),

one was a medium-sized tortoise and the third was a small tortoise.

     One day they went into a restaurant and ordered some cake. While they were waiting for the cake, they

remembered that they hadn't brought any money. "Hey, we forgot to bring money to pay for our cake," the

big tortoise said. "The little tortoise can go home and get it," the medium-sized tortoise said. "He's the youngest,

so he should be the one to go." The little tortoise wasn't very pleased at this, but he knew he shouldn't argue

(争吵) with his elders, so he said, "All right, I'll go. But you must promise not to eat my cake while I'm away."

The large tortoise and the medium-sized tortoise agreed, and the little tortoise set off for home to get some

money.

     A few days later, the big tortoise said to the medium-sized tortoise, "Let's eat the little tortoise's cake.

I'm hungry again." "So am I," the medium-sized tortoise said, and reached for the cake. As she did so, the

little tortoise shouted from near the door of the restaurant, "If you touch my cake, I won't go and get the

money!"

1. The three tortoises _____. [ ]

A. didn't know each other

B. knew each other

C. lived in a restaurant

D. were very poor

2. The three tortoises found they didn't take money with them _____.[ ]

A. when they were ordering the cake

B. after they ate up the cake

C. before they went into the restaurant

D. after they ordered the cake

The little tortoise _____. [ ]

A. didn't mind getting the money

B. couldn't find the money

C. wanted to share his cake

D. agreed to get the money

4. The little tortoise _____. [ ]

A. didn't go very far after a few days

B. came back very quickly

C. had some money with him

D. believed in the other two tortoises

5. The two elders decided to eat the little tortoise's cake because _____. [ ]

A. they felt hungry again

B. they wanted to leave at last

C. the cake was so nice to eat

D. they were angry with the little tortoise

单项选择题