1. Write a variable declaration for each of the following (don’t forget to include the type):
    1. x which equals 86
    2. e which equals 2.71
    3. name which equals Alicia

 

  1. If I want to store the value 5 in the variable y, can I do it this way?  If not, what is the correct way.

5 = y;

 

  1. Which of these are proper identifiers:
    1. 5numbers
    2. #6verb
    3. BIG_NUMBER
    4. someVar
    5. _number

 

  1. What will the following code produce:
    1. System.out.println(“\”Nevermore!\”\n\t\\The Raven”);

 

  1. What is the value of x for the following?
    1. x = 5/2;
    2. x = 5%2;
    3. x = 5/2.0;

 

  1. What will be printed out?

int x = 1979;

String s1 = "Shakedown, ";

System.out.println(s1 + x + “!”);

 

  1. Write down all the different ways to:
    1. Increment a by 1
    2. Decrement cheese by 3
    3. Multiply and save the value of x by 2

 

  1. simplify the following expressions:
    1. 2 * 5 + 3 * 4 – 6
    2. 17 / 3
    3. (6 + 7) * 2 / 3
    4. 17%3

 

 

 

 

 

 

 

 

 

 

 

 

Practice Multiple Choice

  1. Which of the following will print out "Catch 22"

    I.System.out.print("Catch " + 2 + 2);
    II.System.out.print("Catch " + (11 + 11));
    III.System.out.print("Catch " + 11 + 11);

 

    1. I only
    2. II only
    3. III only
    4. I and II only
    5. II and III only

 

  1. Consider the following code segment:

 

int x = 10;

int y = x / 3;

int z = x % 2;

x++;

System.out.println(x);

 

What is printed as a result of executing the code segment above?

 

A.    2

B.    4

C.    10

D.    11

E.     15

 

  1. Consider the following statements:

        String s1 = "One";
        String s2 = "Two";
        s2 = s1;
        s1 = "Three";

    After the code executes, what will be the value of the object referenced by s2?

 

    1. “One”
    2. “Two”
    3. “Three”
    4. “” (the empty string)
    5. The object that s2 references will be null.

 

Practice Free Response (50% of the test):

 

Write a class that represents an equilateral triangle.  An equilateral triangle will have a constructor that takes the length of a side and the height of the triangle.  It will also have a default constructor that initializes the side and height to 0.  Equilateral triangles will have 2 methods: one to calculate the area and one to calculate the perimeter.  There should also be getter methods for the length of the side and the height.  Write a main method to test your class.