目录
2. (单选题)Suppose x is 1. What is x after x -= 1?
3. (单选题)Which of the following is incorrect?
4. (单选题)What is the value of (double)(5/2)?
5. (单选题)The "less than or equal to" comparison operator in Java is .
6. (单选题)What is 1 + 1 + 1 + 1 + 1 == 5?
7. (单选题)What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?
10. (单选题)Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?
11. (单选题)Given |x| >= 4, which of the following is true?
15. (单选题)What is i after the following for loop?int y = 0;for (int i = 0; i < 10; ++i) { y += i;}
16. (单选题)Which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100?
24. (多选题)To add a value 1 to variable x, you write
25. (多选题)What is the output from System.out.println((int)Math.random() * 4)?
一、单选题
1. (单选题)What is i printed in the following code?
public class Test {
public static void main(String[] args) { int j = 0;
int i = j++ + j * 5;
System.out.println("What is i? " + i);
}
}
- A. 0
- B. 1
- C. 5
- D. 6
我的答案: C
2. (单选题)Suppose x is 1. What is x after x -= 1?
- A. 0
- B. 1
- C. 2
- D. -1
- E. -2
我的答案: A
3. (单选题)Which of the following is incorrect?
- A. int x = 9;
- B. long x = 9;
- C. float x = 1.0;
- D. double x = 1.0;
我的答案: C
4. (单选题)What is the value of (double)(5/2)?
- A. 2
- B. 2.5
- C. 3
- D. 2.0
- E. 3.0
我的答案: D
5. (单选题)The "less than or equal to" comparison operator in Java is .
- A. <
- B. <=
- C. =<
- D. <<
- E. !=
我的答案: B
6. (单选题)What is 1 + 1 + 1 + 1 + 1 == 5?
- A. true
- B. false
- C. There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.
我的答案: A
7. (单选题)What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?
- A. true
- B. false
- C. There is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true.
我的答案: C
8. (单选题)The following code displays .
double temperature = 50; if (temperature >= 100)
System.out.println("too hot"); else if (temperature <= 40) System.out.println("too cold"); else
System.out.println("just right");
- A. too hot
- B. too cold
- C. just right
- D. too hot too cold just right
我的答案: C
9. (单选题)Suppose x = 1, y = -1, and z = 1. What is the output of the following statement? (Please indent the statement correctly first.)
if (x > 0) if (y > 0)
System.out.println("x > 0 and y > 0"); else if (z > 0)
System.out.println("x < 0 and z > 0");
- A. x > 0 and y > 0;
- B. x < 0 and z > 0;
- C. x < 0 and z < 0;
- D. no output.
我的答案: B
10. (单选题)Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?
- A. 9
- B. 10
- C. 11
我的答案: B
11. (单选题)Given |x| >= 4, which of the following is true?
- A. x >= 4 && x <= -4
- B. x >= 4 || x <= -4
- C. x >= 4 && x < -4
- D. x >= 4 || x < -4
我的答案: B
12. (单选题)What is y displayed in the following code?
public class Test1 {
public static void main(String[] args) { int x = 1;
int y = x = x + 1; System.out.println("y is " + y);
}
}
- A. y is 0.
- B. y is 1 because x is assigned to y first.
- C. y is 2 because x + 1 is assigned to x and then x is assigned to y.
- D. The program has a compile error since x is redeclared in the statement int y = x = x + 1.
我的答案: C
13. (单选题)How many times will the following code print "Welcome to Java"?
int count = 0;
while (count++ < 10) { System.out.println("Welcome to Java");
}
- A. 8
- B. 9
- C. 10
- D. 11
- E. 0
我的答案: C