- Write
a variable declaration for each of the following (don’t forget to include
the type):
- x
which equals 86
- e
which equals 2.71
- name
which equals Alicia
- 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;
- Which
of these are proper identifiers:
- 5numbers
- #6verb
- BIG_NUMBER
- someVar
- _number
- What
will the following code produce:
- System.out.println(“\”Nevermore!\”\n\t\\The
Raven”);
- What
is the value of x for the following?
- x =
5/2;
- x =
5%2;
- x =
5/2.0;
- What
will be printed out?
int
x = 1979;
String
s1 = "Shakedown, ";
System.out.println(s1 + x + “!”);
- Write
down all the different ways to:
- Increment
a by 1
- Decrement
cheese by 3
- Multiply
and save the value of x by 2
- simplify
the following expressions:
- 2
* 5 + 3 * 4 – 6
- 17
/ 3
- (6
+ 7) * 2 / 3
- 17%3
Practice Multiple
Choice
- 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);
- I
only
- II
only
- III
only
- I
and II only
- II
and III only
- 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
- 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?
- “One”
- “Two”
- “Three”
- “”
(the empty string)
- 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.