Name: 
 

Sample Test Using Java as the Programming Language



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

1. 

If String name = "George W. Bush"; then the instruction name.length(); will return 14.
 

2. 

If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false.
 

3. 

A variable of type boolean will store either a 0 or a 1.
 

4. 

In Java, the symbol “=” and the symbol “==” are used synonymously (interchangeably).
 

5. 

The statements x++; and ++x; will accomplish the same thing.
 

6. 

The statement { } is a legal block.
 

7. 

The statement if(a >= b) a++; else b--; will do the same thing as the statement if (a < b) b--; else a++;.
 

8. 

An if statement may or may not have an else clause, but an else clause must be part of an if statement.
 

9. 

Java methods can return only primitive types (int, double, float, char, boolean, etc).
 

10. 

Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
 

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

11. 

Consider the following statement:
System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
This statement will output ___ lines of text
a.
1
d.
4
b.
2
e.
5
c.
3
 

12. 

If you want to output the text "hi there", including the quote marks, which of the following could do that?
a.
System.out.println("hi there");
c.
System.out.println("\"hi there");
b.
System.out.println(""hi there"");
d.
System.out.println("\"hi there\"");
 

13. 

A Java variable is the name of a
a.
numeric data value stored in memory
c.
data value stored in memory that can not change its type during the program’s execution
b.
data value stored in memory that can not change during the program’s execution
d.
data value stored in memory that can change both its value and its type during the program’s execution
 

14. 

What value will z have if we execute the following assignment statement?    
float z = 5 / 10;     
a.
z will equal 0.0
c.
z will equal 5.0
b.
z will equal 0.5
d.
z will equal 0.05
 

15. 

Which of the following is true regarding the mod operator, %?
a.
It can only be performed on int values and its result is a double
c.
It can only be performed on float or double values and its result is an int
b.
It can only be performed on int values and its result is an int
d.
It can only be performed on float or double values and its result is a double
 

16. 

Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates?
for(int i=0;i<5;i++)
                   x += i;
a.
0
c.
5
b.
4
d.
10
 

17. 

How many times will the following loop iterate?
int x = 10;

do 
{
    System.out.println(x);
    x--;
} while (x > 0);
a.
0 times
d.
10 times
b.
1 time
e.
11 times
c.
9 times
 

18. 

How many times will the following loop iterate?

int x = 10;
while (x > 0)
{
   System.out.println(x);
   x--;
}
a.
0 times
d.
10 times
b.
1 time
e.
11 times
c.
9 times
 

19. 

The following nested loop structure will execute the inner most statement (x++) how many times?

for(int j = 0; j < 100; j++)
   for(int k = 100; k > 0; k--)
      x++;
a.
100
d.
20,000
b.
200
e.
1,000,000
c.
10,000
 

20. 

A variable whose scope is restricted to the method where it was declared is known as a(n)
a.
parameter
d.
public instance data
b.
global variable
e.
private instance data
c.
local variable
 



 
Check Your Work     Reset Help