Quiz #2 ----------------------------------------- 1. (4 points) What would the values of the following expressions be: a. 68 % 204 b. 1 + 2 * 4 % 2 ANSWER: 2. (3 points) The following code won’t compile. Fix the error in it. Please use casting in your answer. double a = 4.532; int wholeNumber = a; ANSWER: 3. (6 points) A class contains a method and the first line of the method is shown below. Assume that the rest of the method is correctly implemented and answer the questions below. public void garbleSpeech( String speech ) { a. What is the method name? b. What arguments, if any, are required when garbleSpeech is called? c. What, if anything, is returned? ANSWER: 4. (10 points) What is the output of the program below? Be sure to include any assumptions you make about how the program runs to get partial credit. public class Buzz { private static int i = 5; private static String str = new String(“fizz”); public static void fizzed( int i ) { if ( (( i % 5) == 0) && ((i % 7) == 0) ) { System.out.print(“fizzbuzz”); } else { if ((i%5) == 0) System.out.print( str ); else { if ((i%7) == 0) System.out.print(“buzz”); else System.out.print(i); } } } public static void main( String[] args ) { System.out.println(“In the main method”); fizzed( 49 ); fizzed( i ); System.out.println(); System.out.println( str == “fizz” ); } } // Buzz ANSWER: 5. (4 points) Assume the following if statement exists in a class. What is wrong with it and how would you fix it? long inky = 500; if ( 1 < inky < 1000 ) { System.out.println( inky ); } ANSWER: 6. (4 points) What is the output for the following chunk of code?: long giggle = 3; int a = 0, b = 0; switch( giggle ) { case 1: a = 1; break; case 2: b = 2; case 3: a = 3; case 4: b = 4; case 5: a = 5; break; default: break; } System.out.println("a is " + a + " and b is " + b); ANSWER: 7. (6 points) What is wrong with the following piece of code and why? int i = 1; if ( i ) { System.out.println("I saw i!"); } ANSWER: 8. (10 points) Write a series of conditional statements that will find the minimum of two integer numbers a and b. You can put the conditional statement inside the method construct we have written for you. You may not use the Math class in this question. public int minimum( int a, int b ) { int min = a; // put ANSWER code here // return our minimum to whomever called this method return min; } 9. (4 points) Write one statement that declares an array named lizards, creates the array, and fills it with the values “Binky”, “Zeller”, and “Stellar”. Answer: 10. (6 points) Turn the following statement into an equivalent if set of statements. You may assume that count has previously been created and is an integer. switch ( count ) { case 1 : System.out.println( “1” ); break; case 2 : System.out.println( “2” ); default: System.out.println( “default” ); } Answer: 11. (8 points) What is the output of the following program? public class MysteryQuestion2 { public static void main(String[] args) { for (int outerCount=0; outerCount < 4; outerCount++) { for (int count=0; count<=outerCount; count++) { System.out.print("-"); } System.out.println(">?"); } } }