| CIT 591 Final Exam, Fall 2007 | Name ______________________________ |
Please keep answers brief and to the point. Adding information that I did not ask for will not improve your grade, but will cost you points if you get it wrong. In answers where case matters, be sure I can tell your capital letters from your lowercase letters.
| Statements |
Result |
|
|---|---|---|
| a. |
int
x = 5; x = x++; System.out.println(x); |
5 |
| b. |
int
x = 2; while (x < 100) x *= 5; System.out.println(x); |
250 |
| c. |
int
x = 10; System.out.println(x < 5 ? "A" : x > 10 ? "B" : "C"); |
C |
| d. |
int
x = 2; switch(x) { case 1: x = 7; case 2: x = x + 1; case 3: x = 5 * x; default: x = -x; } System.out.println(x); |
-15 |
| e. |
int
x = 2; do { x *= x; } while (x < 100); System.out.println(x); |
256 |
| f. |
int
x = 1; for (x = 1; x < 5; x = x + 2) x--; System.out.println(x); |
5 |
| g. |
int
x = 2; if (++x > 0 || ++x < 5) x = -x; System.out.println(x); |
-3 |
| h. |
String
s =
"abcdefghij";
System.out.println(s.substring(3, 6)); |
def |
| i. |
int
a = 1, b = 4, c =
2, d = 3; System.out.println(a + b + "=" + c + d); |
5=23 |
| j. |
Random
rand = new
Random(); System.out.println(rand.nextInt(1)); |
0 |
s.myArray is a rectangular
two-dimensional array of
strings. Set the int variable size
to the
total number of locations in the array.boolean variable
b to true
if string s contains the letter
'A', and to false
otherwise.JButton named clearButton
(so that the user cannot click it)."Insufficient
room".true if
variable myDog
holds an instance of the Poodle class, and
print false
otherwise.odds
containing the
first five odd positive integers.score
is
negative.int variable cost
to the rounded
value of the double
variable price.ArrayList named names
that can hold only strings.obj to null
unless
it is an instance of a class that implements the Comparable
interface.| (Write your Javadoc comment here) /** * Tests whether its input parameter is odd. * * @param n The number to be tested. * @return true if the number is odd, false otherwise. */ |
static
boolean isOdd(int n) { |
isOdd method is in class MyMath.Write the
method header:true for the number
1.false for the
number 0.true for the
number -1.}Observer
interface.Person
has an instance variable String name, and
assume that variable friend holds an object
of type Person. Write the complete method you
need to add to the Person class in order to
make the statement System.out.println(friend) print
out that person's name.