Pre-AP® Computer Science Quiz 12.01- 07 Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have at least 20 seconds for each question.
Title the quiz as shown below The quiz starts in ONE minute. Name Period Date Quiz 12.01-07 1. 12. 2. 13. 3. 14. 4. 15. 5. 16. 6. 17. 7. 18. 8. 19. 9. 20. 10. 21. 11. EC.
Question 01 Which of the following is actually a class? int double char boolean String
Question 02 Which of the following is a set of characters that behave as a single unit? int double char boolean String
Question 03 The characters in a String can include Upper-case letters Lower-case letters Numerical digits Symbols like ! @ # $ % ^ & * ( ) _ + All of the above
Question 04 True or False In Java, a String is really just an array of characters. (a) True (b) False
Question 05 Consider this Java statement: String name = “John”; Which of the following is the string variable? String name “John”
Question 06 Consider this Java statement: String name = “John”; Which of the following is the string literal? String name “John”
Question 07 Which of the following constructs a String object? String s1 = "Aardvark"; String s2 = new String( ); s2 = "Aardvark"; String s3 = new String("Aardvark"); String s4 = new String(s3); char animal[ ] = {'A', 'a', 'r', 'd', 'v', 'a', 'r', 'k'}; String s5 = new String(animal); All of the above
Question 08 With String, the plus [ + ] and plus-equals [ += ] operators perform addition. subtraction. multiplication. division. concatenation.
Question 09 Which String method allows access to an individual character in a String object? (a) indexOf (b) charAt (c) length (d) replace (e) lastIndexOf (f) valueOf
Question 10 Which String method allows you to access the “tan" in "Standard“? (a) indexOf (b) charAt (c) length (d) replace (e) substring (f) valueOf
Question 11 Which String method allows you find the location of the “tan" in "Standard". (a) indexOf (b) charAt (c) length (d) replace (e) substring (f) valueOf
Question 12 Which String method returns the number of characters in the String? (a) indexOf (b) charAt (c) length (d) replace (e) substring (f) valueOf
Question 13 Which String method replaces all occurrences of one character with another? (a) indexOf (b) charAt (c) length (d) replace (e) substring (f) valueOf
Question 14 Which String method converts primitive data type values to String values? (a) indexOf (b) charAt (c) length (d) replace (e) substring (f) valueOf
Question 15 Which String method has the same name as a field from a Java static array ? (a) indexOf (b) charAt (c) length (d) replace (e) substring (f) valueOf
Question 16 Which of the following string literals would NOT be affected by either String methods toUpperCase or toLowerCase? John Smith </*{-(12345)-}*\> Hello123 QWERTY wh@ is th@?
Question 17 If x and y are simple/primitive data types, and you need to check if they are equal, which command would you use? if ( x = y ) if ( x == y ) if ( x != y ) if ( x.equals(y) ) if ( !x.equals(y) )
Question 18 If x and y are String objects, and you need to check if they are equal, which command would you use? if ( x = y ) if ( x == y ) if ( x != y ) if ( x.equals(y) ) if ( !x.equals(y) )
Question 19 Which values of s1 and s2 will cause these 2 statements to display different outputs? System.out.println(s1.indexOf(s2)); System.out.println(s1.lastIndexOf(s2)); s1 = “Texas”; s2 = “Tex”; s1 = “Mississippi”; s2 = “iss”; s1 = “Utah”; s2 = “ah”; s1 = “Tennessee”; s2 = “qwerty”;
Question 20 True or False All of the methods of the String class are object methods. (a) True (b) False
Question 21 String animal = "Giraffe"; What is the output of the program segment below? String animal = "Giraffe"; String s = animal.substring(1,3); System.out.println(s); Gir (b) ira (c) Gi (d) ir
Extra Credit Assume s stores “Hello, I live at 123 Baker St.” Which program statement alters the value of the String object s. (a) s.substring(7,13); (b) s.replace('l','w'); (c) s.toUpperCase(); (d) s.toLowerCase(); (e) All of the above (f) None of the above