JavaOOP2015复习题1
JavaOOP复习题1
Part I: Multiple Choice Questions:
1.24 % 5 is _____
A. 2
B. 0
C. 4
D. 1
E. 3
醉赤壁林俊杰
Key:c
#
2.If you attempt to add an int, a byte, a long, and a double, the result will be a __________ value.
A. int
B. long
C. byte
澳洲木瓜膏>桃红复含宿雨
D. double
Key:d
#
3.What is the result of 45 / 4?
A. 11
B. 12
C. 10
D. 11.25
Key:a
#
4.In Java, the word true is ________.两个喇叭一起吹歇后语
A. a Boolean literal
B. a Java keyword
C. same as value 0
猴子头饰D. same as value 1
Key:a
#
5.The following code displays ___________.
double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
el if (temperature <= 40)
美美的幸福生活
System.out.println("too cold");
el
System.out.println("just right");
A. too hot
B. too cold
C. too hot too cold just right
D. just right
Key:d
#
6.The "less than or equal to" comparison operator in Java is __________.
A. <<
B. =<
C. !=
D. <=
E. <
Key:d
#
克癀胶囊7.Analyze the following code fragments that assign a boolean value to the variable even.
Code 1:
if (number % 2 == 0)
even = true;
el
even = fal;
Code 2:
even = (number % 2 == 0) ? true: fal;
Code 3:
even = number % 2 == 0;
A. Code 3 has a syntax error, becau you attempt to assign number to even.
B. Code 2 has a syntax error, becau you cannot have true and fal literals in the conditional expression.
C. All three are correct, but Code 1 is preferred.
D. All three are correct, but Code 2 is preferred.
E. All three are correct, but Code 3 is preferred.
Key:e
#
8.How many times will the following code print "Welcome to Java"? int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 10);
A. 10
B. 8
C. 0
D. 9
E. 11
Key:e
#
9.What is the value in count after the following loop is executed?
int count = 0;
我想对老师说作文
do {
System.out.println("Welcome to Java");
} while (count++ < 9);
System.out.println(count);
A. 11
B. 0
C. 9
D. 8
E. 10
Key:e
#
10.What is the number of iterations in the following loop:
for (int i = 1; i <= n; i++) {
// iteration
}
A. 2*n
B. n
C. n - 1
D. n + 1
Key:b
#
11.What is the output for y?
int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}
System.out.println(y);
A. 45
B. 12
C. 13
D. 10
E. 11
Key:a
#
12.What is i after the following for loop?
int y = 0;
for (int i = 0; i<10; ++i) {
y += i;
}
A. 9
B. 10
C. undefined
D. 11
Key:c
#
13.__________ is to implement one method in the structure chart at a time from the top to the bottom.
A. Stepwi refinement
B. Top-down approach
C. Bottom-up and top-down approach
D. Bottom-up approach
Key:b
#
14.Analyze the following code.
public class Test {
public static void main(String[] args) {
System.out.println(max(1, 2));