Name: 
 

AP Computer Science Java - Unit 1 Practice MC Test



Multiple Choice
Identify the letter of the choice that best completes the statement or answers the question.
 

 1. 

The syntax of a language ...
a.
is the set of all words and symbols in the language.
b.
consists of the rules for combining words into statements..
c.
defines the rules for interpreting the meaning of statements.
d.
is simply used for storage.
 

 2. 

Which type of programming error is the most difficult to debug?
a.
Syntax
c.
Logic
b.
Run-time
d.
Omission
 

 3. 

Which of the following is not a primitive data type?
a.
int
c.
String
b.
char
d.
boolean
 

 4. 

Which variable type would be the best choice to store a letter grade?
a.
int
c.
char
b.
double
d.
String
 

 5. 

What is the output from the following statements?

double x = 3.1415;
System.out.println(EasyFormat.format(x, 1, 3));
a.
3
c.
3.141
b.
3.14
d.
3.142
 

 6. 

Which keyword in Java declares a variable whose value cannot change?
a.
final
c.
constant
b.
const
d.
new
 

 7. 

The expression 3 + 2 * 5 - 1 yields:
a.
24
c.
11
b.
12
d.
20
 

 8. 

Which of the following mixed-mode arithmetic expressions yields 8.0?
a.
5 / 2 * 4.0
c.
5.0 / 2 * 4
b.
5 / 2.0 * 4
d.
5.0 / 2.0 * 4
 

 9. 

Which of the following identifiers is invalid?
a.
FIRSTNAME
c.
gross_income
b.
number3
d.
9innings
 

 10. 

Which of the following expressions will result in an integer value?
a.
3 / 2 + 8 / 9 - 5
c.
3 / 2.0 + 8 / 9 - 5
b.
3 / 2 + 8 / 9 - 5.0
d.
3 / 2 + 8.0 / 9 - 5
 

 11. 

Which of the following expressions will result in an answer of 3?
a.
(1 + 17 ) % 3
c.
12 % 3 - 1
b.
1 + 17 % 3
d.
5 * 2 % 3
 

 12. 

Which of the following does NOT contain a syntax error?
a.
double w, x, y and z;
b.
System.out.println(Hello again!”);
c.
value = keybd.readint();
d.
num = a*(b + c);
 

 13. 

In the assignment statement below, what is the purpose of the (double) used?

int x = 3, y = 2;
double z = (double) x / y;

a.
To double the amount of the answer, like multiplying by 2.
b.
To make sure that the result of the division is a decimal number.
c.
To round the answer to the nearest integer.
d.
To round the answer to the nearest tenth.
 

 14. 

Assume the variable declarations below for this problem:

int x = 3, y = 2, z = x + y;

Which of the following output statements correctly displays the sentence below?

3 + 2 = 5
a.
System.out.print(x + “+” + y + “=” + z);
b.
System.out.print(x + “ + ” + y + “ = ” + z);
c.
System.out.print(x + y + “ = ” + z);
d.
System.out.print(x + y = z);
 

 15. 

What is the value of the expression below?

Math.pow(Math.abs(3-6), Math.sqrt(4))
a.
9
c.
7
b.
8
d.
6
 



 
Check Your Work     Start Over