Name: 
 

Final Exam Review 2



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

 1. 

Which statement will increment total by 1?
a.
total = 1;
c.
total--;
b.
total++;
d.
total += total;
 

 2. 

What will the following statement do?
for ( ;; )
{

}
a.
It will cause an infinite loop.
b.
The loop will be skipped because there is no test.
c.
It will loop the maximum number of times (32,768).
d.
It will cause a syntax error
 
 
Code Segment 1

switch(grade) {
   case 'A' :
      System.out.print("Excellent!");
      break;
   case 'B' :
   case 'C' :
      System.out.print("Well done");
      break;
   case 'D' :
      System.out.print("You passed");
      break;
   case 'F' :
      System.out.print("Better try again");
      break;
   default :
      System.out.print("Invalid grade");
   }
 

 3. 

Given Code Segment 1 and this statement below,what will the output be?
           char grade = 'D';
a.
Better try again
b.
Invalid grade
c.
You passed
d.
Well done
e.
Excellent
 

 4. 

Given Code Segment 1 and this statement below,what will the output be?
           char grade = 'B';
a.
Excellent
b.
Well done
c.
Invalid grade
d.
You passed
e.
Better try again
 

 5. 

Given Code Segment 1 and this statement below,what will the output be?
           char grade = 'Q';
a.
Better try again
b.
You passed
c.
Excellent
d.
Well done
e.
Invalid grade
 

 6. 

Given this variable declaration, what data can be stored in the variable ?
float number;
a.
false
c.
0, 47.978
b.
‘Q’
d.
0, 9
 

 7. 

Which of the following for headers is not valid?
a.
All of the above.
b.
for ( int i = 0; i < 10; i++ )
c.
int i = 0;
for ( ; i < 10; i++ )
d.
for ( int i = 0; int j = 5; ; i++ )
 

 8. 

What is wrong with the following while loop?
      while ( sum <= 1000 )
            sum = sum – 30;

a.
sum = sum – 30 should be sum = sum + 30 or else the loop may never end
b.
There should be a semicolon after while ( sum <= 1000 ).
c.
The parentheses should be braces.
d.
Braces are required around sum = sum – 30;.
 

 9. 

The logical operator for OR is
a.
||
c.
==
b.
!
d.
&&
 

 10. 

In Java, the condition ( 4 > y > 1 )
a.
does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ).
b.
evaluates correctly and could be replaced by ( 4 > y && y > 1 ).
c.
evaluates correctly and could not be replaced by ( 4 > y && y > 1 ).
d.
does not evaluate correctly and should not be replaced by ( 4 > y && y > 1 ).
 

 11. 

Each pass through a loop is called
a.
an iteration
c.
an evaluation
b.
a culmination
d.
an enumeration
 

 12. 

The &&, ||, and ! operators are called..
a.
Selection
c.
Arithmetic
b.
Logical
d.
Boolean
 

 13. 

Evaluate int(4.0/3.0)
a.
1
c.
error
b.
0.3
d.
1.3333333…
 

 14. 

The statement x += 2; is equivalent to
a.
++x;
c.
x = x + 1 = x + 1;
b.
x++;
d.
x = x + 2;
 

 15. 

In a switch statement what must come after every case?
a.
break
c.
switch
b.
default
d.
cout
 

 16. 

What is the final value of x after performing the following operations?
int x = 21;
double y = 6;
double z = 14;
y = x / z;
x = 5.5 * y;
a.
8.25
c.
5.5
b.
5.
d.
8.
 

 17. 

What will print from thest statements ?
    int number;
    System.out.print (number);

a.
The value last stored in the memory location reserved for that variable
b.
A value of zero.
c.
A randomly assigned value.
d.
No value.
 

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

 18. 

The following statement will repeat 50 times.        
      for (int i = 1; i<50; i++)
 

 19. 

The Boolean operator for AND is ||.
 

 20. 

When using an if .. else statement, indentation is demanded by the compiler.
 

 21. 

The variable names count and Count are considered the same in Java. In otherwords, Java is a case insensitive language.
 

 22. 

Evaluate the following Logical expressions as TRUE or FALSE.
  ( ! ( 7 == 7 ))
 

 23. 

The double slash ( // ) is used to identify syntax errors.
 

 24. 

A do loop statement iterates at least once before evaluating the condition.
 

 25. 

What output is produced by the segment of code shown below.
int x = 25;
if (x == 25)
   System.out.println("True");
else
   System.out.println("False");
 

 26. 

This code segment will output “Sue Ellen”. Watch out for poor indentation!

int x = 12;
if (x > 12)
{System.out.print("BUFFY");
System.out.print("SUE");}
System.out.print("ELLEN");
 

 27. 

This code segment will output “green jeans”.
int x = 12;
if(x > 12){
if(x < 15)
System.out.print("blue "); }
else System.out.print("green ");
System.out.println("jeans"););
 

 28. 

Evaluate the following Logical expressions as TRUE or FALSE.
(5 + 4 < 3 && 7 + 3 <= 20 )
 

 29. 

Given this declaration
    String name1, name2;
The following statements will compare the two strings and determine if they are the same.
     
    if(name1==name2){
         System.out.print(“Identical”);
    }
 

 30. 

Evaluate the following Logical expressions as TRUE or FALSE.
!0
 

 31. 

Evaluate the following Logical expressions as TRUE or FALSE.
  ( 'a' == 97 )
 

 32. 

You can use symbols like % and $ in variable names.
 

 33. 

Include the statement import java.iostream; in order to use  System.out.print() .
 

 34. 

“byte” is a keyword in Java.
 



 
Check Your Work     Start Over