1. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
You don't use a FOR loop with Strings
Read the String backwards (from last element to first element). (*)
Parse the String. (*)
Search for a specific character or String inside of the String. (*)
[Correct] Correct
2. Which of the following methods can be used to replace a segment in a string with a new string? Mark for Review
(1) Points
remove(String oldString, String newString)
replaceAll(String oldString, String newString) (*)
replaceAll(String newString)
substring(int start, int end, String newString)
None of the above. There is no replaceAll(String newString) method with one argument.
[Incorrect] Incorrect. Refer to Section 3 Lesson 1.
3. Identify the method, of those listed below, that is not available to both StringBuilders and Strings? Mark for Review
(1) Points
indexOf(String str)
charAt(int index)
length()
delete(int start, int end) (*)
[Correct] Correct
4. Which of the following are true about parsing a String?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
It is not possible to parse a string using regular expressions.
It is possible to use the String.split() method to parse a string. (*)
It is a way of dividing a string into a set of sub-strings. (*)
It is possible to use a for loop to parse a string. (*)
[Incorrect] Incorrect. Refer to Section 3 Lesson 1.
5. A linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1 (*)
2 or more
None
[Correct] Correct
6. A non-linear recursive method is less expensive than a linear recursive method.
True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 3 Lesson 3.
7. Which case does a recursive method call last? Mark for Review
(1) Points
Recursive Case
Convergence Case
Basic Case
Base Case (*)
None of the above
[Correct] Correct
8. Consider the following recursive method recur(x, y). What is the value of recur(4, 3)?
public static int recur(int x, int y) {
if (x == 0) {
return y;
}
return recur(x - 1, x + y);
} Mark for Review
(1) Points
10
13 (*)
9
12
[Correct] Correct
9. Which of the following correctly defines Matcher? Mark for Review
(1) Points
A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
A class in the java.util.regex package that stores the format of a regular expression.
A regular expression symbol that represents any character.
A method of dividing a string into a set of sub-strings.
[Correct] Correct
10. Square brackets are a representation for any character in regular expressions "[ ]".
True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 3 Lesson 2.
11. Consider that you are writing a program for analyzing feedback on the video game you have developed. You have completed everything except the segment of code that checks that the user's input, String userI, is a valid rating. Note that a valid rating is a single digit between 1 and 5 inclusive. Which of the following segments of code returns true if the user's input is a valid rating?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return userI.matches("[1-5].*");
return userI.matches("[1-5]{1}"); (*)
return userI.matches("[1-5]"); (*)
return userI.matches("{1-5}");
[Incorrect] Incorrect. Refer to Section 3 Lesson 2.
12. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for Review
(1) Points
Matcher m = new Matcher();
Matcher m = p.matcher(str); (*)
Matcher m = str.matcher(p);
Matcher m = new Matcher(p,str);
[Correct] Correct
13. Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group for the last name considering that the string contactsName is always in the format lastName_firstName? Mark for Review
(1) Points
Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)
Pattern namePattern = Pattern.compile("first_last");
Pattern namePattern = new Pattern(last{5},first{5});
Pattern namePattern = new Pattern();
None of the above.
[Correct] Correct
14. Your teacher asks you to write a segment of code that returns true if String str contains zero or one character(s) and false otherwise. Which of the following code segments completes this task?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return str.matches(".?"); (*)
return str.contains(".");
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
return str.matches("[a-z]*");
[Incorrect] Incorrect. Refer to Section 3 Lesson 2.
15. What is the correct explanation of when this code will return true?
return str.matches(".*[0-9]{6}.*"); Mark for Review
(1) Points
Any time that str contains two dots.
Any time that str contains a sequence of 6 digits. (*)
Any time that str has between zero and nine characters followed by a 6.
Any time str contains a 6.
Always.
[Correct] Correct
(1) Points
(Choose all correct answers)
You don't use a FOR loop with Strings
Read the String backwards (from last element to first element). (*)
Parse the String. (*)
Search for a specific character or String inside of the String. (*)
[Correct] Correct
2. Which of the following methods can be used to replace a segment in a string with a new string? Mark for Review
(1) Points
remove(String oldString, String newString)
replaceAll(String oldString, String newString) (*)
replaceAll(String newString)
substring(int start, int end, String newString)
None of the above. There is no replaceAll(String newString) method with one argument.
[Incorrect] Incorrect. Refer to Section 3 Lesson 1.
3. Identify the method, of those listed below, that is not available to both StringBuilders and Strings? Mark for Review
(1) Points
indexOf(String str)
charAt(int index)
length()
delete(int start, int end) (*)
[Correct] Correct
4. Which of the following are true about parsing a String?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
It is not possible to parse a string using regular expressions.
It is possible to use the String.split() method to parse a string. (*)
It is a way of dividing a string into a set of sub-strings. (*)
It is possible to use a for loop to parse a string. (*)
[Incorrect] Incorrect. Refer to Section 3 Lesson 1.
5. A linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1 (*)
2 or more
None
[Correct] Correct
6. A non-linear recursive method is less expensive than a linear recursive method.
True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 3 Lesson 3.
7. Which case does a recursive method call last? Mark for Review
(1) Points
Recursive Case
Convergence Case
Basic Case
Base Case (*)
None of the above
[Correct] Correct
8. Consider the following recursive method recur(x, y). What is the value of recur(4, 3)?
public static int recur(int x, int y) {
if (x == 0) {
return y;
}
return recur(x - 1, x + y);
} Mark for Review
(1) Points
10
13 (*)
9
12
[Correct] Correct
9. Which of the following correctly defines Matcher? Mark for Review
(1) Points
A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
A class in the java.util.regex package that stores the format of a regular expression.
A regular expression symbol that represents any character.
A method of dividing a string into a set of sub-strings.
[Correct] Correct
10. Square brackets are a representation for any character in regular expressions "[ ]".
True or false? Mark for Review
(1) Points
True
False (*)
[Incorrect] Incorrect. Refer to Section 3 Lesson 2.
11. Consider that you are writing a program for analyzing feedback on the video game you have developed. You have completed everything except the segment of code that checks that the user's input, String userI, is a valid rating. Note that a valid rating is a single digit between 1 and 5 inclusive. Which of the following segments of code returns true if the user's input is a valid rating?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return userI.matches("[1-5].*");
return userI.matches("[1-5]{1}"); (*)
return userI.matches("[1-5]"); (*)
return userI.matches("{1-5}");
[Incorrect] Incorrect. Refer to Section 3 Lesson 2.
12. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for Review
(1) Points
Matcher m = new Matcher();
Matcher m = p.matcher(str); (*)
Matcher m = str.matcher(p);
Matcher m = new Matcher(p,str);
[Correct] Correct
13. Consider designing a program that organizes your contacts alphabetically by last name, then by first name. Oddly, all of your contacts' first and last names are exactly five letters long.
Which of the following segments of code establishes a Pattern namePattern with a group for the first name and a group for the last name considering that the string contactsName is always in the format lastName_firstName? Mark for Review
(1) Points
Pattern namePattern = Pattern.compile("(.{5})_(.{5})"); (*)
Pattern namePattern = Pattern.compile("first_last");
Pattern namePattern = new Pattern(last{5},first{5});
Pattern namePattern = new Pattern();
None of the above.
[Correct] Correct
14. Your teacher asks you to write a segment of code that returns true if String str contains zero or one character(s) and false otherwise. Which of the following code segments completes this task?(Choose Two) Mark for Review
(1) Points
(Choose all correct answers)
return str.matches(".?"); (*)
return str.contains(".");
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
return str.matches("[a-z]*");
[Incorrect] Incorrect. Refer to Section 3 Lesson 2.
15. What is the correct explanation of when this code will return true?
return str.matches(".*[0-9]{6}.*"); Mark for Review
(1) Points
Any time that str contains two dots.
Any time that str contains a sequence of 6 digits. (*)
Any time that str has between zero and nine characters followed by a 6.
Any time str contains a 6.
Always.
[Correct] Correct
Komentar
Posting Komentar