CSCE 111 – Exam 1 FORM A TRUE/FALSE

Transcription

CSCE 111 – Exam 1 FORM A TRUE/FALSE
CSCE 111 – Exam 1
FORM A
TRUE/FALSE
The word import in a Java program is a reserved word.
T
JOptionPane uses an instance method to get keyboard input from the user. F
The Java Virtual Machine is responsible for executing Java byte code. T
The contents of a variable cannot be changed during runtime, only while the code is compiling. F
Program code can only have one execution path(flow). F
Because the || operator performs short-circuit evaluation, your boolean expression will generally be
evaluated faster if the subexpression that is most likely to be true is on the left. T
7. When two Strings are compared using the equals method, their case is important. T
8. The if/else statement will execute one group of statements if its boolean expression is true or
another group if its boolean expression is false. T
9. Suppose we have the following declarations: F
int i = 4, j = 1;
The expression, (i *(j / i) ) == 1, evaluates True or False?
10. In nested if statements, if the inner if statement evaluates to false, the outer if is automatically false. F
11. In Java, if x is declared as
1.
2.
3.
4.
5.
6.
final int x = 5;
the assignment expression
x += 3;
will change variable x’s value to 3 only if 3 is greater than its current value. F
12. Java runs differently on different CPU architectures. F
13. In computers, data stored in binary form is represented as a series of 0s and 1s.
T
14. The following statement is valid:
double xyz = 4,867.50; F
15. It doesn’t matter where you declare the variables, as long as they are somewhere in the program. F
MULTIPLE CHOICE
16. The major components of a typical computer system consist of:
a.
b.
c.
d.
e.
The CPU
Input/output devices
Main memory
Secondary storage devices
All of the above
17. A program is a sequence of instructions stored in:
a.
b.
c.
d.
e.
The CPU
The motherboard
Software
Firmware
Memory
18. What will be the values of ans, x, and y after the following statements are executed?
int ans = 0, x = 15, y = 25;
if ( x >= y)
{
ans = x + 10;
x -= y;
}
else
{
if (x < y){
ans = y + 10;
}
y += x;
}
a.
b.
c.
d.
e.
ans = 0, x = 15, y = 25
ans = 25, x = -10, y = 25
ans = 25, x = 15, y = 40
ans = 35, x = 25, y = 40
None of the above
19. What is the output of the following code fragment?
String x = “Howdy Aggies!”;
String y = “Gig em!”;
if (y.charAt(2) == x.charAt(7))
System.out.println(y.length());
else
System.out.println(x.length());
a.
b.
c.
d.
e.
6
7
9
12
13
20. A runtime error is usually the result of:
a.
b.
c.
d.
e.
A logical error
A syntax error
A compilation error
All of the above
B or C only.
21. The purpose of validating the results of the program is:
a.
b.
To create a model of the program
To correct syntax errors
c.
d.
e.
To correct runtime errors
To make sure the program solves the problem
B and C
22. The name of a variable is known as its
a.
b.
c.
d.
e.
Constant
Data type
Object
Identifier
Method
23. Each different type of CPU has its own:
a.
b.
c.
d.
e.
Syntax
Firmware
Software
Operating System
Machine language
24. RAM is usually:
a.
b.
c.
d.
e.
Secondary storage
An input/output device
A static type of memory, used for permanent storage
A volatile type of memory, used only for temporary storage
A type of memory only used to store random values
25. Key words are:
a.
b.
c.
d.
e.
The data names in your program
Words that have a special meaning in the programming language
Words that cannot be re-defined by the programmer
Symbols or words that perform operations on one or more operands
B and C
26. A Java program must have one of these:
a.
b.
c.
d.
e.
Variable
Comment
System.out.println(); statement
Main method
Scanner definition
27. In Java, ___________ must be declared before they can be used.
a.
b.
c.
d.
e.
Memory blocks
Literals
Key words
Comments
None of the above
28. If the following Java statements are executed, what will be displayed?
System.out.println("The top three winners are");
System.out.print("George, the Giant\n");
System.out.print("Ben, the Barbarian");
System.out.println("Aaron, the Alligator");
a.
b.
c.
d.
e.
The top three winners are
George, the Giant
Ben, the Barbarian
Aaron, the Alligator
The top three winners are
George, the Giant
Ben, the BarbarianAaaron, the Alligator
The top three winners are
George, the Giant\nBen, the BarbarianAaron, the Alligator
The top three winners are George, the Giant\nBen, the BarbarianAaron, the Alligator
There is an error in the code
29. When the + operator is used with strings, it is known as the:
a.
b.
c.
d.
e.
Assignment operator
String concatenation operator
Addition operator
Combined assignment operator
Print operator
30. Which of the following is a primitive data type?
a.
b.
c.
d.
e.
short
long
float
int
All of the above
31. The short data type may contain values in the following range of values
a.
b.
c.
d.
e.
true or false
-128 to + 127
- 2,147,483,648 to +2,147,483,647
- 32,768 to +32,767
None of the above
32. What is the value of a?
double a = 25 / 4 + 4 * 10 % 3;
a. 10.25
b. 0.5
c. 3.5
d. 7.0
e. 1.25
33. What will be displayed as a result of executing the following code?
int x = 8, y = 20;
x += 32;
if ( x > 32) y /= 4;
System.out.println("x = " + x + ", y = " + y);
a.
b.
c.
d.
e.
x = 8, y = 20
x = 32, y = 4
x = 32, y = 20
x = 40, y = 4
x = 40, y = 5
34. In the following Java statement what value is stored in the variable name?
String name = "James Bond";
a.
b.
c.
d.
e.
James Bond
The memory address where "James Bond" is located
The word name
A sequence of bits representing the ascii character values of “James Bond”
C and D
35. When a computer is running a program, the CPU is engaged in a process formally known as:
a.
b.
c.
d.
e.
The fetch/decode/execute cycle
The decrypt/validate/commit cycle
Low-level machine mode
Parallax data execution
Decision selection
36. Variables are:
a.
b.
c.
d.
e.
Symbolic names made up by the programmer that represents locations in the computer's RAM
Reserved words
Symbolic names made up by the programmer whose values cannot be changed
Operators that perform operations on one or more operands
None of the above
37. What will be displayed as a result of executing the following code?
public class Test
{
public static void main(String[] args){
int value1 = 9;
System.out.println(value1);
int value2 = 45;
System.out.println(value2);
System.out.println(value3);
int value3 = 16;
}
}
a.
b.
c.
d.
e.
9
45
16
94516
9 45 16
value1
value2
value3
Nothing, this is an error
38. What does the following code display?
int f = 9;
double g = 12.1;
System.out.printf("%d %f\n", f, g);
a.
b.
c.
d.
e.
%d %f\n
%d %f
%9 %12.1\n
9 12
9 12.1000
39. Which of the following is not a valid string in Java?
a. “A”
b. "\u0048\u0065\u006C\u006C\u006F World"
c. “radius = \”20\””
d. “radius = ‘20’”
e. All of the above are valid
40. What will be printed when the following code is executed?
double x = 98765.456;
DecimalFormat formatter = new DecimalFormat("#,##0.0");
System.out.println(formatter.format(x));
a.
b.
c.
d.
e.
98765.4
98760.0
98,765.4
98,765.5
There is an error in how DecimalFormat is used
41. In an if/else statement, if the boolean expression is false,
a.
b.
c.
d.
e.
the first statement or block is executed
all statements or blocks are executed
no statements or blocks are executed
the else statement block is executed first, then followed by the if block
the statement or block following the else is executed
42. What is the value of ans after the following code has been executed?
int a = 27;
int b = 10, ans = 53;
if (a < b);
ans += b;
a.
b.
c.
d.
e.
10
27
53
63
90
43. What would be the value of x after the following statements were executed?
int x = 10;
switch (x)
{
case 10: x += 15;
case 12: x -= 5;
case 20: x = 10;
break;
default: x *= 3;
}
a.
b.
c.
d.
e.
5
10
20
25
30
44. What would be the value of bonus after the following statements are executed?
int bonus, sales = 500;
if (sales > 400)
bonus = 100;
if (sales > 250)
bonus = 50;
if (sales > 50)
bonus = 25;
else
bonus = 0;
a.
b.
c.
d.
e.
100
50
25
0
None of the above
45. If chr is a character variable, which of the following if statements is written correctly?
a.
if (chr = "h")
b.
c.
d.
e.
if (chr == "e")
if (chr = 'l')
if (chr == 'l')
if (chr == o)
46. What is the output of the following code segment?
System.out.print(“Print\t” + 3 + “\tthis”);
a. Print3this
b. Print
3
this
c. Print
3this
d. Print\t3\tthis
e. Invalid statement
47. A syntax error differs from a runtime error in that :
a. syntax errors occur while a program is running
b. syntax errors are often missed be the compiler
c. syntax errors are harder to fix than runtime errors
d. syntax errors are reported by the compiler
e. they are the same
48. In the Java programming language, an argument is used to ________________.
a. provide values to an invoked method
b. override the object’s default method definition
c. define constants in any given program
d. perform mathematical tasks (especially algebraic) in Java
e. let the Java compiler know the purpose of the method
49. The import statement :
a. allows programs to access classes that are already defined elsewhere
b. retrieves user input
c. copies text, verbatim, from a file
d. is needed if the class to be imported is in the same package
e. none of the above
50. The keyword 'new':
a. starts a new program
b. clears the value from a variable
c. generates a random integer
d. allocates memory for the object
e. none of the above