java-chapt8
What will be printed after the following code is executed? String str = "abc456"; int i = 0; while ( i < 6 ) { if (!Character.isLetter(str.charAt(i)) System.out.println(Character.toUpperCase(charAt(i))); i++; } (a) 456 (b) ABC456 (c) ABC (d) abc456
A, Character Testing and Conversion with the Character Class
Two ways of concatenating two Strings are (a) Use the concat() method or use the + between the two Strings (b) Use the concatenate() method or use the + between the two Strings (c) Use the contenate() method or the concat() method (d) Use the concat() method or the trim() method
A, More String Methods
In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the data items is (a) Token (b) Delimiter (c) Buffer (d) Separator
A, Tokenizing Strings
True/FalseThe valueOf() method accepts a value of any primitive data type as an argument and returns a string representation of the value.
True, More String Methods
True/FalseStringBuffer objects are not immutable.
True, The StringBuffer Class
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.lastIndexOf("ov", 14); (a) 15 (b) 16 (c) 0 (d) -1
D, More String Methods
What would be the results of executing the following code? StringBuffer strbuff = new StringBuffer(12); strbuff.append("The cow"); strbuff.append("jumped over the"); strbuff.append("moon."); (a) The program would crash (b) strbuff would equal "The cow jump" (c) strbuff would equal "The cow jumped over the" (d) strbuff would equal "The cow jumped over the moon."
D, The StringBuffer Class
For the following code, how many times would the while loop execute? StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great."); while (strToken.hasMoreTokens) { System.out.println(strToken.nextToken()); } (a) 1 (b) 3 (c) 5 (d) 7
D, Tokenizing Strings
To convert the double variable, d = 543.98, to a string, use the following statement. (a) String str = Double.toString(d); (b) String str = double.toString(d); (c) String str = double(d); (d) String str = d.Double.toString(str);
A, Wrapper Classes for the Numeric Data Types
What will be the value of matches after the following code has been executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str2); (a) True (b) False (c) moon (d) The cow
Answer: B, More String Methods—no period in str2
What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17); (a) diddle (b) diddl (c) , didd (d) Iddle
B, More String Methods
Given the following statement, which of the following is not true? str.insert(8, 32); (a) str is a StringBuffer type object (b) The insert will start at position 32 (c) The starting position for the insert is 8 (d) The constant 32 will be inserted
B, The StringBuffer Class
What will be the value of strbuff after the following statements are executed? StringBuffer strbuff = new StringBuffer("We have lived in Chicago, Trenton, and Atlanta." strbuff.replace(26, 33, "Tampa"); (a) We have lived in Tampa, Trenton, and Atlanta. (b) We have lived in Chicago, Tampa, and Atlanta. (c) We have lived in Chicago, Trenton, and Tampa. (d) We have lived in Chicago, Tampaon, and Atlanta.
B, The StringBuffer Class
To convert the string, str = "285" to an integer and store it in the variable x, use the following statement (a) integer x = str; (b) integer x = Integer.parseInt(str); (c) integer x = Integer.integer(str); (d) integer x = str,Integer.parseInteger;
B, Wrapper Classes for the Numeric Data Types
If String str = "ABCDEFGHI," what will be returned from Character.toLowerCase(str.charAt(5))? (a) e (b) E (c) f (d) F
C, Character Testing and Conversion with the Character Class
Although it is not normally useful to create objects from the wrapper classes, programmers might use wrapper classes because (a) They create immutable classes (b) They are easy to use (c) They provide static methods that are very useful (d) (b) and (c)
C, Introduction to Wrapper Classes
The parameterless constructor for a StringBuffer object gives the object enough storage space to hold ___ (a) 0 characters (b) 8 characters (c) 16 characters (d) 32 characters
C, The StringBuffer Class
If you do not specify delimiters in the StringToken constructor, which of the following cannot be a delimiter? (a) Space (b) Tab (c) Semicolon (d) Newline
C, Tokenizing Strings
Which of the following statements will print the maximum value an integer variable may have? (a) System.out.println(MAX_VALUE); (b) System.out.println(integer.MAX_VALUE); (c) System.out.println(Integer.MAX_VALUE); (d) System.out.println(INTEGER.MAX_VALUE);
C, Wrapper Classes for the Numeric Data Types
Use the following import statement when using the character wrapper class (a) import java.Char (b) import java.lang.Char (c) import java.String (d) No import statement is needed
D, Character Testing and Conversion with the Character Class
What will be the tokens in the following statement? StringTokenizer strToken = new StringTokenizer("January 1, 2004", ", ", true); (a) January, 1, 2004 (b) comma and space (c) January, 1, 2004, space (d) January, 1, 2004, space, comma
D, Tokenizing Strings
What does the following statement do? Float number = new Float(8.8); (a) It creates a Float object (b) It initializes that object to 8.8 (c) It assigns the object's address to the number variable (d) All of the above
D, Wrapper Classes for the Numeric Data Types
True/FalseIf a non-letter argument is passed to the toLowerCase or toUpperCase method, a boolean false is returned.
False, Character Testing and Conversion with the Character Class
True/FalseIf a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one for each delimiter character.
False, Tokenizing Strings
True/FalseYou cannot assign a value to a wrapper class object.
False, Wrapper Classes for the Numeric Data Types