Name: 
 

ch2



True/False
Indicate whether the statement is true or false.
 

 1. 

Data can be categorized as variable or constant.
 

 2. 

Variable names must start with a letter and cannot be any reserved keyword.
 

 3. 

In a variable declaration, the data type is not always required.
 

 4. 

A programmer can declare two variables of the same type in a single statement. For example:

int x = 7, y = 15;
 

 5. 

Variables of different types can be declared in a single statement. For example:

int count, double salary;
 

 6. 

You can declare variables at any point within a method prior to their first use.
 

 7. 

A division operation must always be performed before a modulus operation.
 

 8. 

You can perform modulus operations using floating-point values.
 

 9. 

All variables must be declared at the beginning of a method.
 

 10. 

When a float value is converted to an int, it is always rounded up.
 

 11. 

All escape sequences start with a backslash.
 

 12. 

By convention, variable names in Java start with an upper case.
 

Modified True/False
Indicate whether the statement is true or false. If false, change the identified word or phrase to make the statement true.
 

 13. 

The number 700 is referred to as a(n) literal constant. ____________________

 

 14. 

To distinguish them from class names, variable names usually begin with uppercase letters. ____________________

 

 15. 

A(n) byte variable can hold only one of two values -- true or false. ____________________

 

 16. 

You type constant character values in double quotes. ____________________

 

 17. 

You type String constants between single quotation marks. ____________________

 

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

 18. 

The modulus operator is _____.
a.
mod
c.
%
b.
/
d.
*
 

 19. 

The result of the following expression is _____.

       6 + 2 * 3 - 4
a.
-8
c.
8
b.
4
d.
20
 

 20. 

An escape sequence begins with a(n) _____.
a.
~
c.
\
b.
%
d.
&
 

 21. 

Which of the following is not an escape sequence?
a.
\\
c.
\t
b.
\?
d.
\n
 

 22. 

The value of x in the following statement is _____.

      int x = 9 % 4;
a.
1
c.
3
b.
2
d.
4
 

 23. 

When adding a float, a double, and an int, the result is a(n) _____.
a.
float
c.
int
b.
double
d.
long
 

 24. 

In the following statement, the value of x is _____.

     int x = 20 / 4 + 1
a.
6
c.
5
b.
4
d.
3
 

 25. 

A person's first name is most likely stored in a(n) _____.
a.
char
c.
int
b.
String
d.
long
 

 26. 

1 is the result of which of the following?
a.
13 % 4
c.
8 % 4
b.
13.0 % 4.0
d.
8.0 % 4.0
 

 27. 

The following is an example of a(n) _____.

     int i;
a.
initialization
c.
declaration
b.
assignment
d.
constant
 

 28. 

The value of an integer divided by an integer is a(n) _____.
a.
float
c.
int
b.
double
d.
byte
 

 29. 

5 + 2 / 2 yields _____.
a.
6
c.
3.5
b.
3
d.
5
 

 30. 

8 * 3 - 5 yields _____.
a.
-16
c.
19
b.
24
d.
17
 

 31. 

6 - 1 * 7 yields _____.
a.
35
c.
41
b.
-1
d.
33
 

 32. 

9 / 4 + 6 yields _____.
a.
8
c.
0
b.
8.25
d.
15
 

 33. 

The identifier in the following statement is _____.

    double salary = 30000;
a.
double
c.
=
b.
salary
d.
30000
 

 34. 

The value of the following expression is _____.

    2 * 3 / 4
a.
1
c.
1.50
b.
0
d.
2
 

Completion
Complete each statement.
 

 35. 

char, int, and double are examples of ____________________ data types.
 

 

 36. 

The = sign is the ____________________ operator in the statement int myAge = 25;.
 

 

 37. 

The ____________________ type has only two values.
 

 



 
Check Your Work     Start Over