Section 3 - Quiz 1 L1-L3
(Answer all questions in this section)
1. 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.
Incorrect. Refer to Section 3 Lesson 2.
2. Which of the following methods for the String class take a regular expression as a parameter and returns true if the string matches the expression? Mark for Review
(1) Points
compareTo(String regex)
equals(String regex)
matches(String regex) (*)
equalsIgnoreCase(String regex)
Incorrect. Refer to Section 3 Lesson 2.
3. What is the function of the asterisk (*) in regular expressions? Mark for Review
(1) Points
Indicates that the preceding character may occur 0 or 1 times in a proper match.
Indicates that the preceding character may occur 0 or more times in a proper match. (*)
The asterisk has no function in regular expressions.
Indicates that the preceding character may occur 1 or more times in a proper match.
Incorrect. Refer to Section 3 Lesson 2.
4. Which of the following correctly defines Matcher? Mark for Review
(1) Points
A regular expression symbol that represents any character.
A method of dividing a string into a set of sub-strings.
A class in the java.util.regex package that stores the format of a regular expression.
A class in the java.util.regex package that stores the matches between a pattern and a string. (*)
Correct
5. Matcher has a find method that checks if the specified pattern exists as a sub-string of the string being matched.
True or false? Mark for Review
(1) Points
True (*)
False
Correct
6. Which of the following correctly defines Pattern? Mark for Review
(1) Points
A regular expression symbol that represents any character.
A method of dividing a string into a set of sub-strings.
A class in the java.util.regex package that stores the format of a regular expression. (*)
A class in the java.util.regex package that stores matches.
Incorrect. Refer to Section 3 Lesson 2.
7. 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 = str.matcher(p);
Matcher m = new Matcher(p,str);
Matcher m = p.matcher(str); (*)
Incorrect. Refer to Section 3 Lesson 2.
8. A linear recursion requires the method to call which direction? Mark for Review
(1) Points
Forward
Backward (*)
Both forward and backward
None of the above
Incorrect. Refer to Section 3 Lesson 3.
9. 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
10. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review
(1) Points
True
False (*)
Correct
11. A non-linear recursive method calls how many copies of itself in the recursive case? Mark for Review
(1) Points
0
1
2 or more (*)
Correct
12. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply) Mark for Review
(1) Points
(Choose all correct answers)
Parse the String. (*)
Read the String backwards (from last element to first element). (*)
Search for a specific character or String inside of the String. (*)
You don't use a FOR loop with Strings
Incorrect. Refer to Section 3 Lesson 1.
13. Split is a method for Strings that parses a string by a specified character, or, if unspecified, by spaces, and returns the parsed elements in an array of Strings.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
14. Which of the following correctly initializes a StringBuilder? Mark for Review
(1) Points
StringBuilder sb = "This is my String Builder";
StringBuilder sb = StringBuilder(500);
StringBuilder sb = new StringBuilder(); (*)
None of the above.
Incorrect. Refer to Section 3 Lesson 1.
15. Which of the following are true about the method split? Mark for Review
(1) Points
(Choose all correct answers)
It returns an array of strings. (*)
It can be used with a string as a parameter. (*)
It's default, with no specified parameter, is parsing by spaces.
It can be used with a regular expression as a prameter. (*)
Incorrect. Refer to Section 3 Lesson 1.
1. Matcher has a find method that checks if the specified pattern exists as a sub-string of the string being matched.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 2.
2. Which of the following methods for the String class take a regular expression as a parameter and returns true if the string matches the expression? Mark for Review
(1) Points
compareTo(String regex)
matches(String regex) (*)
equals(String regex)
equalsIgnoreCase(String regex)
Incorrect. Refer to Section 3 Lesson 2.
3. Which of the following does not correctly match the regular expression symbol to its proper function? Mark for Review
(1) Points
"{x}" means there must be x occurrences of the preceding character in the string to be a match.
"?" means there may be zero or one occurrences of the preceding character in the string to be a match.
"+" means there may be zero or more occurrences of the preceding character in the string to be a match. (*)
"{x,}" means there may be x or more occurrences of the preceeding character in the string to be a match.
"{x,y}" means there may be between x and y occurrences of the preceding character in the string to be a match.
Incorrect. Refer to Section 3 Lesson 2.
4. 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.
Incorrect. Refer to Section 3 Lesson 2.
5. The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]{2}/[0-9]{2}".
Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 2.
6. In a regular expression, {x} and {x,} represent the same thing, that the preceding character may occur x or more times to create a match.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
7. 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.
Incorrect. Refer to Section 3 Lesson 2.
8. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply) Mark for Review
(1) Points
(Choose all correct answers)
Search for a specific character or String inside of the String. (*)
Parse the String. (*)
You don't use a FOR loop with Strings
Read the String backwards (from last element to first element). (*)
Incorrect. Refer to Section 3 Lesson 1.
9. Which of the following are true about the method split? Mark for Review
(1) Points
(Choose all correct answers)
It's default, with no specified parameter, is parsing by spaces.
It can be used with a regular expression as a prameter. (*)
It can be used with a string as a parameter. (*)
It returns an array of strings. (*)
Incorrect. Refer to Section 3 Lesson 1.
10. Identify the method, of those listed below, that is not available to both StringBuilders and Strings? Mark for Review
(1) Points
length()
indexOf(String str)
charAt(int index)
delete(int start, int end) (*)
Incorrect. Refer to Section 3 Lesson 1.
11. Which of the following methods are specific to StringBuilders? Mark for Review
(1) Points
append
delete
insert
replace
All of the above. (*)
Incorrect. Refer to Section 3 Lesson 1.
12. A non-linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1
2 or more (*)
None
Correct
13. The base case condition can work with a constant or variable. True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 3.
14. Forward thinking helps when creating linear recursive methods. True or false? Mark for Review
(1) Points
True
False (*)
Correct
15. A linear recursive method directly calls how many copies of itself in the recursive case? Mark for Review
(1) Points
0
1 (*)
2 or more
Incorrect. Refer to Section 3 Lesson 3.
1. Which of the following correctly initializes a Matcher m for Pattern p and String str? Mark for Review
(1) Points
Matcher m = str.matcher(p);
Matcher m = p.matcher(str); (*)
Matcher m = new Matcher(p,str);
Matcher m = new Matcher();
Incorrect. Refer to Section 3 Lesson 2.
2. 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.
Incorrect. Refer to Section 3 Lesson 2.
3. 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? Mark for Review
(1) Points
(Choose all correct answers)
return str.contains(".");
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
return str.matches(".?"); (*)
return str.matches("[a-z]*");
Incorrect. Refer to Section 3 Lesson 2.
4. In a regular expression, {x} and {x,} represent the same thing, that the preceding character may occur x or more times to create a match.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
5. 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.
Incorrect. Refer to Section 3 Lesson 2.
6. The following code correctly initializes a pattern with the regular expression "[0-9]{2}/[0-9]{2}/[0-9]{2}".
Pattern dateP = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{2}");
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 2.
7. Matcher has a find method that checks if the specified pattern exists as a sub-string of the string being matched.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 2.
8. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review
(1) Points
True
False (*)
Correct
9. Which case handles the last recursive call? Mark for Review
(1) Points
The primary case
The base case (*)
The convergence case
The recursive case
The secondary case
Incorrect. Refer to Section 3 Lesson 3.
10. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 3 Lesson 3.
11. A linear recursive method directly calls how many copies of itself in the recursive case? Mark for Review
(1) Points
0
1 (*)
2 or more
Incorrect. Refer to Section 3 Lesson 3.
12. Which of the following are true about the method split? Mark for Review
(1) Points
(Choose all correct answers)
It can be used with a string as a parameter. (*)
It's default, with no specified parameter, is parsing by spaces.
It can be used with a regular expression as a prameter. (*)
It returns an array of strings. (*)
Incorrect. Refer to Section 3 Lesson 1.
13. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply) Mark for Review
(1) Points
(Choose all correct answers)
Read the String backwards (from last element to first element). (*)
Search for a specific character or String inside of the String. (*)
You don't use a FOR loop with Strings
Parse the String. (*)
Incorrect. Refer to Section 3 Lesson 1.
14. Which of the following correctly initializes a StringBuilder? Mark for Review
(1) Points
StringBuilder sb = "This is my String Builder";
StringBuilder sb = StringBuilder(500);
StringBuilder sb = new StringBuilder(); (*)
None of the above.
Incorrect. Refer to Section 3 Lesson 1.
15. Which of the following are true about parsing a String? Mark for Review
(1) Points
(Choose all correct answers)
It is not possible to parse a string using regular expressions.
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. (*)
It is possible to use the String.split() method to parse a string. (*)
Incorrect. Refer to Section 3 Lesson 1.
1. Which of the following correctly defines a StringBuilder? Mark for Review
(1) Points
A class that represents a string-like object. (*)
There is no such thing as a StringBuilder in Java.
A method that adds characters to a string.
A class inside the java.util.regex package.
Incorrect. Refer to Section 3 Lesson 1.
2. Using the FOR loop method of incrementing through a String is beneficial if you desire to: (Choose all that apply) Mark for Review
(1) Points
(Choose all correct answers)
Search for a specific character or String inside of the String. (*)
Parse the String. (*)
Read the String backwards (from last element to first element). (*)
You don't use a FOR loop with Strings
Incorrect. Refer to Section 3 Lesson 1.
3. What class is the split() method a member of? Mark for Review
(1) Points
Parse
String (*)
Array
StringBuilder
Correct
4. Split is a method for Strings that parses a string by a specified character, or, if unspecified, by spaces, and returns the parsed elements in an array of Strings.
True or false? Mark for Review
(1) Points
True
False (*)
Correct
5. 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? Mark for Review
(1) Points
(Choose all correct answers)
return str.matches("[a-z]*");
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
return str.contains(".");
return str.matches(".?"); (*)
Incorrect. Refer to Section 3 Lesson 2.
6. 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.
Incorrect. Refer to Section 3 Lesson 2.
7. What does the dot (.) represent in regular expressions? Mark for Review
(1) Points
An indication for one or more occurrences of the preceding character.
A match for any character. (*)
A range specified between brackets that allows variability of a character.
Nothing, it is merely a dot.
Incorrect. Refer to Section 3 Lesson 2.
8. One benefit to using groups with regular expressions is that you can segment a matching string and recall the segments (or groups) later in your program.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 2.
9. A regular expression is a character or a sequence of characters that represent a string or multiple strings.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 3 Lesson 2.
10. 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? Mark for Review
(1) Points
(Choose all correct answers)
return userI.matches("[1-5]"); (*)
return userI.matches("{1-5}");
return userI.matches("[1-5]{1}"); (*)
return userI.matches("[1-5].*");
Incorrect. Refer to Section 3 Lesson 2.
11. Which of the following correctly defines a repetition operator? Mark for Review
(1) Points
A symbol that represents any character in regular expressions.
A method that returns the number of occurrences of the specified character.
Any symbol in regular expressions that indicates the number of occurrences a specified character appears in a matching string. (*)
None of the above.
Incorrect. Refer to Section 3 Lesson 2.
12. A non-linear recursive method is less expensive than a linear recursive method. True or false? Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 3 Lesson 3.
13. Forward thinking helps when creating linear recursive methods. True or false? Mark for Review
(1) Points
True
False (*)
Correct
14. A linear recursive method can call how many copies of itself? Mark for Review
(1) Points
1 (*)
2 or more
None
Incorrect. Refer to Section 3 Lesson 3.
15. 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
Incorrect. Refer to Section 3 Lesson 3.
6. Square brackets are a representation for any character in regular expressions "[ ]".
True or false? Mark for Review
(1) Points
True
False (*)
Incorrect. Refer to Section 3 Lesson 2.
Which of the following methods are specific to StringBuilders? Mark for Review
(1) Points
append
delete
insert
replace
All of the above. (*)
Incorrect. Refer to Section 3 Lesson 1.
0 komentar:
Posting Komentar