Chapter 10 Quiz - Gaddis Starting Out With Java 5 From...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Gaddis – Starting Out With Java 5 – From Control Structures to Objects Chapter 10 – Text Processing and More About Wrapper Classes Multiple Choice 1. Few programmers use wrapper classes because a. They are immutable b. They are not easy to use c. They provide useful static functions d. (a) and (b) ANS: D 2. The Character wrapper class provides numerous methods for a. Testing String objects b. Testing and converting char variables c. Converting String variables d. Adding two char variables ANS: B 3. What will be printed after the following code is executed? String str = “abc456”; int i = 0; while ( l < 6 ) { if (Character.isLetter(str.charAt(i)) System.out.println(Character.toUpperCase(charAt(i))); i ++ ; } a. abc456 b. ABC456 c. ABC d. 456 ANS: C 4. If String str = “RSTUVWXYZ”, what will be the value returned from str.charAt(5)? a. U b. V c. W d. X ANS: C 5. If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged. a. True b. False
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ANS: A 6. What will be the value of matches after the following code is executed? boolean matches; String[] productCodes = {“456HI345”, “3456hj”}; matches = productCodes[0].regionMatches(true, 1,productCodes[1], 2, 3) a. 56H b. 56h c. True d. False ANS: C 7. What will be the value of loc after the following code is executed? int loc; String str = “The cow jumped over the moon.” loc = str.indexOf(“ov”); a. 15 b. 16 c. 17 d. 18 ANS: A 8. In the following statement, what data type must recField be: str.getChars(5, 10, recField, 0); a. String b. int c. char d. char[] ANS: D 9. When you are writing a program with String objects that may have unwanted spaces at the beginning or end of the strings, use the ____ method to delete them. a. replace b. trim c. valueOf d. substring ANS: B 10. The valueOf() method accepts a string representation as an argument and returns its equivalent integer value. a. True b. False ANS: B
Background image of page 2
11. StringBuffer objects are immutable. a. True b. False ANS: B 12. The following StringBuffer constructor will StringBuffer str = new StringBuffer(25) a. Give the object, str, 25 bytes of storage and store spaces in them b. Give the object, str, 25 bytes of storage and not store anything in them c. Give the object, str, 25 or more bytes of storage and store spaces in them d. Give the object, str, 0 bytes of storage ANS: B 13. What would be the results of executing the following code? StringBuffer str = new StringBuffer(“Little Jack Horner”) str.append(“sat on the”); str.append(“corner”); a. The program would crash b. str would equal “Little Jack Horner” c. str would equal “Little Jac Horner sat on the” d. str would equal “Little Jack Horner sat on the corner”
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Chapter 10 Quiz - Gaddis Starting Out With Java 5 From...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online