java第二章

1. _____________ System analysis seeks to analyze the data flow and to identify the system’s input and output. When you do analysis, it helps to identify what the output is first, and then figure out what input data you need in order to produce the output.

a. Requirements specification
b. Design
c. Implementation
d. Testing
e. Analysis

#
2. A variable must be declared before it can be used.

a. True
b. False

#
3. Which of the following is a valid identifier?

a. $343
b. 8+9
c. class
d. 9X
e. radius

#
4. To add a to b and store result in b, you write (Note: Java is case-sensitive)

a. b += a;
b. b = A + b;
c. a += b;
d. a = b + a;

#
5. Suppose x is 1. What is x after x -= 1?

a. 2
b. -2
c. -1
d. 0
e. 1

#
6. The keyword _______ must be used to declare a constant.

a. static
b. const
c. int
d. final
e. double

#
7. If you attempt to add an int, a byte, a long, and a double, the result will be a __________ value.

a. double
b. long
c. byte
d. int

#
8. Is 'a' larger than 'A'?

a. No
b. Yes

#
9. You can define a constant twice in a block.

a. false
b. true

#
10. Which of the following are the same as 1545.534?

a. 154553.4e-2
b. 1.545534e+3
c. 0.1545534e+4
d. 1545534.0e-3

#
11. The __________ method parses a string s to an int value.

a. integer.parseInt(s);
b. integer.parseInteger(s);
c. Integer.parseInteger(s);
d. Integer.parseInt(s);

#
12. The result of an integer division is the integer part of the division; the fraction part is truncated.

a. true
b. false

#
13. 5 % 1 is _____

a. 0
b. 2
c. 4
d. 3
e. 1

#
14. Suppose x is 1. What is x after x += 2?

a. 1
b. 0
c. 3
d. 2
e. 4

#
15. To declare an int variable number with initial value 2, you write

a. int number = 2L;
b. int number = 2.0;
c. int number = 2;
d. int number = 2l;

#
16. You can change the value of a constant.

a. true
b. false

#
17. _____ are valid Java identifiers.

a. 3ere
b. 4+4
c. _RE4
d. int
e. $Java

#
18. ____________ is the Java assignment operator.

a. :=
b. =:
c. =
d. ==

#
19. currentTimeMills is a method in the _______ class.

a. Integer
b. Math
c. Double
d. System

#
20. A Java statement ends with a __________.

a. period (.)
b. closing brace
c. comma (,)
d. semicolon (;)

#
21. 5 % 2 is _____

a. 4
b. 0
c. 3
d. 1
e. 2

#
22. Which of the following is the correct expression of character a?

a. '\000a'
b. '\a'
c. "a"
d. 'a'

#
23. Which of these data types requires the most amount of memory?

a. int
b. byte
c. long
d. short

#
24. Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?

a. b
b. d
c. c
d. a

#
25. You can cast a character value to a

n int, or an int to char.

a. false
b. true

#
26.
Any assignment statement can be used as an assignment expression.

a. false
b. true

#
27. Which of the following expression results in a value 1?

a. 15 % 4
b. 25 % 5
c. 37 % 6
d. 2 % 1

#
28. Every letter in a Java keyword is in lowercase?

a. true
b. false

#
29. Which of the following is the correct expression of character 4?

a. '\0004'
b. '4'
c. "4"
d. 4

#
30. To add a value 1 to variable x, you write

a. x = x + 1;
b. x += 1;
c. 1 + x = x;
d. x := 1;
e. x = 1 + x;

#
31. What is x after the following statements?

int x = 2;
int y = 1;
x *= y + 1;


a. x is 1.
b. x is 4.
c. x is 2.
d. x is 3.

#
32. If a program compiles fine, but it terminates abnormally at runtime, then the program suffers __________.

a. a logic error
b. a syntax error
c. a runtime error

#
33. You can always assign a value of long type to a variable of int type without loss of precision.

a. true
b. false

#
34. Which of the following operators has the highest precedence?

a. casting
b. /
c. +
d. *

#
35. You can assign the value in ________ to an int variable.

a. 'x'
b. 93
c. 98.3
d. true

#
36. If a number is too large to be stored in a variable of the float type, it _____________.

a. cannot happen in Java
b. causes underflow
c. causes overflow
d. causes no error

#
37. Which of the following assignment statements is illegal?

a. short s = 10;
b. float f = 34.0;
c. int t = 23;
d. float f = -34;

#
38. 24 % 5 is _____

a. 0
b. 3
c. 1
d. 2
e. 4

#
39. Math.pow(2, 3) returns __________.

a. 8
b. 9.0
c. 8.0
d. 9

#
40. To assign a value 1 to variable x, you write

a. 1 := x;
b. x = 1;
c. x := 1;
d. x == 1;
e. 1 = x;

#
41. What is the printout of the following code:

double x = 10.1;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);


a. x is 10.1 and y is 10.0
b. x is 10.0 and y is 10.0
c. x is 10 and y is 10
d. x is 10.1 and y is 10
e. x is 11 and y is 11

#
42. 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. 1
b. 5
c. 6
d. 0

#
43. Which of the following is a constant, according to Java naming conventions?

a. COUNT
b. read
c. Test
d. MAX_VALUE
e. ReadInt

#
44. pow is a method in the _______ class.

a. Double
b. System
c. Math
d. Integer

#
45. Which of the following assignment statements is correct to assign character 5 to c?

a. char c = '5';
b. char c = "5";
c. char c = "344";
d. char c = 5;

#
46. To assign a double variable d to an int variable x, you write

a. x = (long)d
b. x = d;
c. x = (fl

oat)d;
d. x = (int)d;

#
47. An int variable can hold __________.

a. 120.0
b. "120"
c. 'x'
d. 120
e. "x"

#
48. The Unicode of 'a' is 97. What is the Unicode for 'c'?

a. 96
b. 98
c. 99
d. 97

#
49. Which of the following are correct names for variables according to Java naming conventions?

a. Radius
b. FindArea
c. findArea
d. radius
e. RADIUS

#
50. Which of the following statement prints smith\exam1\test.txt?

a. System.out.println("smith\"exam1\"test.txt");
b. System.out.println("smith"\exam1"\test.txt");
c. System.out.println("smith\\exam1\\test.txt");
d. System.out.println("smith\exam1\test.txt");

#
51. Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.

a. Illegal expression
b. 66
c. A1
d. B

#
52. To declare a constant PI, you write

a. final float PI = 3.14159;
b. final double PI = 3.14159;
c. static double PI = 3.14159;
d. final static PI = 3.14159;

#
53. 25 % 1 is _____

a. 3
b. 1
c. 0
d. 2
e. 4

#
54. What is i printed?
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. 5
b. 6
c. 1
d. 0

#
55. Analyze the following code.

import javax.swing.*;

public class ShowErrors {
public static void main(String[] args) {
int i;
int j;
String s = JOptionPane.showInputDialog(null,
"Enter an integer", "Input",
JOptionPane.QUESTION_MESSAGE);
j = Integer.parseInt(s);

i = (i + 4);
}
}
a. The program compiles and runs fine.
b. The program cannot compile because j is not initialized.
c. The program cannot compile because i does not have an initial value when it is used in i = i + 4;
d. The program compiles but has a runtime error because i does not have an initial value when it is used in i = i + 4;

#
56. Analyze the following code:

public class Test {
public static void main(String[] args) {
int n = 10000 * 10000 * 10000;
System.out.println("n is " + n);
}
}

a. The program displays n is 1000000000000
b. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program is aborted.
c. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an underflow and the program continues to execute because Java does not report errors on underflow.
d. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program continues to execute because Java does not report errors on overflow.
e. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an underflow and the program is aborted.

#
57. To add number to sum, you write

(Note: Java is case-sensitive)

a. sum = Number + sum;
b. number += sum;
c. sum = sum + number;
d. number = sum + number;
e. sum += number;

#
58. Are the following four statements equivalent?
number += 1;
number = number + 1;
number++;
++number;

a. No
b. Yes

#
59. Math.pow(4, 1 / 2) returns __________.

a. 0
b. 2.0
c. 1
d. 2
e. 1.0

#
60. You can define a variable twice in a block.

a. false
b. true

#
61. Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.

a. 66
b. B
c. A1
d. Illegal expression

#
62. To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159.

a. classes
b. methods
c. variables
d. constants

#
63. To assign a double variable d to a float variable x, you write

a. x = (float)d;
b. x = (long)d
c. x = (int)d;
d. x = d;

#
64. -15 % 4 is _____

a. 0
b. -3
c. -2
d. -1
e. -4

#
65. According to Java naming convention, which of the following names can be variables?

a. FindArea
b. totalLength
c. class
d. findArea
e. TOTAL_LENGTH

#
66. -24 % -5 is _____

a. 0
b. -4
c. 4
d. -3
e. 3

#
67. 5 % 3 is _____

a. 0
b. 4
c. 2
d. 3
e. 1

#
68.
Suppose a Scanner object is created as follows:

Scanner input = new Scanner(System.in);

What method do you use to read an int value?


a. input.int();
b. input.nextInteger();
c. input.nextInt();
d. input.integer();

#
69. -5 % 5 is _____

a. -4
b. -3
c. -2
d. 0
e. -1

#
70. Which of these data types requires the least amount of memory?

a. float
b. short
c. byte
d. double

#
71. A variable may be assigned a value only once in the program.

a. true
b. false

#
72. Which of the following statements are the same?

(A) x -= x + 4
(B) x = x + 4 - x
(C) x = x - (x + 4)


a. (A) and (C) are the same
b. (A) and (B) are the same
c. (A), (B), and (C) are the same
d. (B) and (C) are the same

#
73. Which of the following is a constant, according to Java naming conventions?

a. read
b. ReadInt
c. Test
d. MAX_VALUE

#
74. Which of the following expression results in 45.37?

a. (int)(45.378 * 100) / 100
b. (int)(45.378 * 100 / 100)
c. (int)(45.378 * 100) / 100.0
d. (int)(45.378) * 100 / 100.0

#
75. 5 % 5 is _____

a. 3
b. 1
c. 2
d. 4
e. 0

#
76. You can always assign a value of int type to a variable of long type without loss of information.

a. true
b. false

#
77. Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?

a. System.out.println(i + " ");
b. System.out.println((int)i);
c. System.out.println(i);
d. System.out.println((char)i);

#
78. The value of a variable can be changed.

a. true
b. false

#

79. _____________ is a formal process that seeks to understand the problem and document in detail what the software system needs to do.

a. Analysis
b. Testing
c. Requirements specification
d. Implementation
e. Design

#
80. Which of the following expressions will yield 0.5?

a. 1.0 / 2
b. (double) 1 / 2
c. 1 / 2
d. 1 / 2.0
e. (double) (1 / 2)

#
81. The __________ method returns a raised to the power of b.

a. Math.pow(b, a)
b. Math.power(a, b)
c. Math.pow(a, b)
d. Math.exponent(a, b)

#
82. A constant can be defined using using the final keyword.

a. False
b. True

#
83. The compiler checks _______.

a. runtime errors
b. logical errors
c. syntax errors

#
84. The expression (int)(76.0252175 * 100) / 100 evaluates to _________.

a. 76.02
b. 76.03
c. 76.0252175
d. 76

#
85. parseInt is a method in the _______ class.

a. Double
b. System
c. Math
d. Integer

#
86. Which of the following assignment statements is incorrect?

a. i = 1 = j = 1 = k = 1;
b. i = j = k = 1;
c. i = 1; j = 1; k = 1;
d. i == j == k == 1;

#
87. parseDouble is a method in the _______ class.

a. Double
b. System
c. Math
d. Integer

#
88. What is 1 % 2?

a. 2
b. 0
c. 1

#
89. Which of the following assignment statements is illegal?

a. int t = 23;
b. int t = 4.5;
c. short s = 10;
d. float f = -34;
e. int t = (int)false;

#
90. To declare a constant MAX_LENGTH inside a method with value 99.98, you write

a. final double MAX_LENGTH = 99.98;
b. final float MAX_LENGTH = 99.98;
c. double MAX_LENGTH = 99.98;
d. final MAX_LENGTH = 99.98;

#
91. -15 % -4 is _____

a. -4
b. 0
c. -2
d. -3
e. -1

#
92. If you attempt to add an int, a byte, a long, and a float, the result will be a __________ value.

a. int
b. long
c. double
d. float

#
93. Will System.out.println((char)4) display 4?

a. Yes
b. No

#
94. What is the value of (double)(5/2)?

a. 2.0
b. 2.5
c. 3
d. 2
e. 3.0

#
95. The following code fragment reads in two numbers:

Scanner input = new Scanner(System.in);
int i = input.nextInt();
double d = input.nextDouble();

What are the correct ways to enter these two numbers?


a. Enter an integer, two spaces, a double value, and then the Enter key.
b. Enter an integer, an Enter key, a double value, and then the Enter key.
c. Enter a numeric value with a decimal point, a space, an integer, and then the Enter key.
d. Enter an integer, a space, a double value, and then the Enter key.

#
96. Which of the following are correct ways to declare variables?

a. int length; int width;
b. int length; width;
c. int length, int width;
d. int length, width;

#
97. A Java character is stored in __________.

a. two bytes
b. three bytes
c. one byte
d. four bytes

#
98. -24 % 5 is _____

a. -3
b.

-4
c. -2
d. -1
e. 0

#
99. The expression 4 + 20 / (3 - 1) * 2 is evaluated to

a. 25
b. 24
c. 9
d. 4
e. 20

#
100. If you enter 1 2 3, when you run this program, what will be the output?

import java.util.Scanner;

public class Test1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();

// Compute average
double average = (number1 + number2 + number3) / 3;

// Display result
System.out.println(average);
}
}


a. 2.0
b. 1.0
c. 3.0
d. 4.0

#
101. What is the result of 45 / 4?

a. 11.25
b. 10
c. 12
d. 11

#
102. 5 % 4 is _____

a. 4
b. 2
c. 0
d. 1
e. 3

#
103. The __________ method parses a string s to a double value.

a. double.parseDouble(s);
b. Double.parseDouble(s);
c. double.parse(s);
d. Double.parsedouble(s);

#
104. Which of the following assignment statements is correct?

a. char c = "d";
b. char c = 100;
c. char c = "100";
d. char c = 'd';

#
105. -25 % 5 is _____

a. 0
b. 4
c. 1
d. 2
e. 3

#
106. What is x after the following statements?

int x = 1;
x *= x + 1;


a. x is 2.
b. x is 4.
c. x is 3.
d. x is 1.

#
107. To declare an int variable x with initial value 200, you write

a. int x = 200L;
b. int x = 200;
c. int x = 200l;
d. int x = 200.0;

#
108. Analyze the following code.

public class Test {
public static void main(String[] args) {
int month = 09;
System.out.println("month is " + month);
}
}

a. The program displays month is 09
b. The program displays month is 9.0
c. The program displays month is 9
d. The program has a syntax error, because 09 is an incorrect literal value.

#
109. What is the printout of System.out.println('z' - 'a')?

a. z
b. 26
c. 25
d. a

#
110. What is the exact output of the following code?

double area = 3.5;
System.out.print("area");
System.out.print(area);


a. 3.5 3.5
b. area 3.5
c. 3.53.5
d. area3.5

#
111. The expression "Java " + 1 + 2 + 3 evaluates to ________.

a. Java 123
b. Java6
c. Illegal expression
d. Java123
e. java 123

#
112. _______ is the code with natural language mixed with Java code.

a. Pseudocode
b. A flowchart diagram
c. A Java statement
d. Java program

#
113. What is y displayed?

public class Test {
public static void main(String[] args) {
int x = 1;
int y = x + x++;
System.out.println("y is " + y);
}
}

a. y is 3.
b. y is 4.
c. y is 1.
d. y is 2.

#
114. The __________ method displays an input dialog for reading a string.

a. String string = JOptionPane.showInputDialog

("Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);
b. String string = JOptionPane.showInputDialog(null, "Enter a string");
c. String string = JOptionPane.showInputDialog("Enter a string");
d. String string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);
e. String string = JOptionPane.showMessageDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE);

#
115. The System.currentTimeMillis() returns ________________ .

a. the current time in milliseconds since midnight.
b. the current time in milliseconds.
c. the current time in milliseconds since midnight, January 1, 1970.
d. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).
e. the current time.

#
116. The assignment operator in Java is __________.

a. = =
b. :=
c. =
d. <-

#
117. What is "Welcome" + 1 + 1*2?

a. Welcome3
b. Welcome11*2
c. Welcome4
d. Welcome12

#
118. You can cast a double value to _______.

a. int
b. float
c. byte
d. long
e. short

#
119. Which of the following are not valid assignment statements?
a. 55 = x;
b. x += 3;
c. x = 56 + y;
d. x = 55;

#
120. What is y displayed in the following code?

public class Test {
public static void main(String[] args) {
int x = 1;
int y = x++ + x;
System.out.println("y is " + y);
}
}

a. y is 4.
b. y is 3.
c. y is 1.
d. y is 2.

#
121. '3' - '2' + 'm' / 'n' is ______.

a. 1
b. 0
c. 2
d. 3

#
122. Math.pow(4, 1.0 / 2) returns __________.

a. 0
b. 2.0
c. 1.0
d. 2
e. 1

#
123. What is the printout of the following code:

double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);

a. x is 6 and y is 6
b. x is 5 and y is 6
c. x is 6.0 and y is 6.0
d. x is 5.5 and y is 5.0
e. x is 5.5 and y is 5

#
124. What is the value of (double)5/2?

a. 2.0
b. 3.0
c. 2.5
d. 3
e. 2

相关主题
相关文档
最新文档