[Compuscholar] Ch.6 L1-3 Quiz Review
Given the code below, what value is stored in the result variable? String surprise = "quiz"; int result = surprise.length();
4 While an index starts at 0-..., the length of the "quiz" value is dependent on the number of characters in the string
Given the code below, what value is stored in the result variable? String surprise = "Quiz";String result = surprise.toUpperCase();
QUIZ
What is the purpose of the ASCII and Unicode systems?
To represent individual characters with unique numbers
[%5s] Conversion Factor - Adds (*5) Spaces to Output [%.3s] Overall (*3) Characters in Strings [%.4f] Formats to Display to (*4) Decimal Points [%2$s] Refers to the Specific Parameter (*2nd)
[%#s - %5s] Conversion Factor - Adds (*5) Spaces to Output [%.#s - %.3s] Overall (*3) Characters in Strings [%.#f - %.4f] Formats to Display to (*4) Decimal Points [%#$s - %2$s] Refers to the Specific Parameter (*2nd)
What does the result variable contain after the following statement? String result = String.format("%.3s", "abcdef");
abc [.*3*s] *3* Overall Characters in Strings - abc
Given the code below, what value is stored in the result variable? String surprise = "quiz"; boolean result = surprise.contains("Q");
false This is because, while the string surprise contains the character "q" in its result as "*q*uiz", it does not contain the capitalized character "Q"
Given the following code, what will be the value stored in the result and why? String color1 = "RED"; String color2 = "red"; boolean result = color1.equals(color2);
false, because while the letters in each value match, the capitalization is different
What does the result variable contain after the following statement? String result = String.format("humpty dumpty", "sat", "on", "a", "wall");
humpty dumpty
What does the result variable contain after the following statement? String result = String.format("humpty %2$s", "humpty", "dumpty");
humpty dumpty String.format("*humpty* %2$s", "humpty", "dumpty"); [%s] Displays String [2$] Refers to 2nd Parameter [*humpty*] Apart of the print statement ("Humpty....") [humpty] 1st Parameter [dumpty] 2nd Parameter Translation: *humpty*.....2nd Parameter (Dumpty)
Given the code below, without knowing the exact contents of the strings, what can always be said about result1 and result2? String s1 = ... String s2 = ... boolean result1 = s1.equals(s2); boolean result2 = s2.equals(s1);
result1 and result2 will have the same value
Given the following code, what will be the value stored in the result and why? String color1 = "RED";String COLOR2 = "red";boolean result = color1.equalsIgnoreCase(COLOR2);
true, because the equalsIgnoreCase() method ignores capitalization and just compares the letters
Given the following code, what will be the value stored in the result and why? String color1 = "red"; String color2 = "red"; boolean result = color1.equals(color2);
true, because the two string values have exactly the same characters and capitalization
Given the code below, what value is stored in the result variable? String surprise = "quiz";String result = surprise.substring(1,4);
uiz
Given the code below, what value is stored in the result variable? String surprise = "quiz"; char result = surprise.charAt(3);
z
What does the result variable contain after the following statement? String result = "Captain," + "incoming" + "message";
Captain,incomingmessage
String result = String.format("I'll take %5s please", "2");
I'll take 2 please [%5s] Conversion Factor - Adds Spaces to Output [5s] Amount of Spaces: 5 [s] First Parameter - 2 (Automatically used as s)