1. The result of 10/2.0 is A) an int B) a double C) a float D) a String E) none of the above

  2. To save the result of 100 * Math.log(2.0) into a String, you can add the following in front of the expression A) String s = (String) B) String s = “” + C) String s = atoi( D) String s = ftoa( E) none of the above

  3. The following will set x to be what value? x = (12>3) ? 12: 3 A) 12 B) 3 C) ¼ D) 4 E) none of the above

  4. The result of x %= 3 when x starts off as 20 is A) 6 B) 6.66 C) 0 D) 2 E) none of the above

  5. Of the following data types, which can have an integer copied into it without being explicitly cast? A) int B) boolean C) double D) both A and C E) A, B and C

  6. Which of the following within a String allows one to add a single “ character to a String? A) “ B) “” C) \”” D) /” E) none of the above

  7. Which of the following will calculate the squareroot of a double z? A) Math.square(z) B) z.sqrt() C) Math.pow(-2) D) Math.sqrt(z) E) none of the above

For the following questions write on your answer sheet T if the statement is true, f otherwise

  1. If one has a method in a superclass and a subclass named the same, by default an object of the subclass type will call the superclass' version of the method

  2. If you define a private class j within a class q, class j can only be used within class q.

  3. Indexes in Strings in Java start counting at 1

  4. It is impossible to cast an object of one class to an object of another class.
    A long variable can store values larger than what an int can hold


  5. In order to extract a specific character in a String, you can use the getChar() method built into the String class.

  6. While doubles store numbers, one cannot use all of the mathematical operators (such as + - * / and such) that one can use with integers.

  7. compareTo returns a boolean value that lets you know only if two strings have exactly the same content or not

  8. I am evil Homer! I am evil Homer!

For the following problems write out SHORT answers on your answer sheet

  1. Given a string named s, write a single line of code that will convert the string into an integer named i (you can assume these variables exist) (worth 2 points)

  2. Write a line of code that will translate an integer named q into a string called s1 (you can assume that these variables are already declared) (worth 1 point)

  3. Set a double named glaven to the built in Java math value for PI * 2