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 Incorrect. Refer to Section 3 Lesson 2.
2. 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 Incorrect. Refer to Section 3 Lesson 2.
3. 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 (*)
Incorrect Incorrect. Refer to Section 3 Lesson 2.
4. 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 Incorrect. Refer to Section 3 Lesson 2.
5. 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
What is the function of the asterisk (*) in regular expressions? Mark for Review
(1) Points
Indicates that the preceding character may occur 0 or more times in a proper match. (*)
Indicates that the preceding character may occur 1 or more times in a proper match.
The asterisk has no function in regular expressions.
Indicates that the preceding character may occur 0 or 1 times in a proper match.
Incorrect Incorrect. Refer to Section 3 Lesson 2.
7. 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(".?"); (*)
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
return str.contains(".");
return str.matches("[a-z]*");
Incorrect Incorrect. Refer to Section 3 Lesson 2.
8. Which of the following are true about parsing a String?(Choose Three) Mark for Review
(1) Points
(Choose all correct answers)
It is a way of dividing a string into a set of sub-strings. (*)
It is possible to use the String.split() method to parse a string. (*)
It is not possible to parse a string using regular expressions.
It is possible to use a for loop to parse a string. (*)
Incorrect Incorrect. Refer to Section 3 Lesson 1.
9. 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)
Read the String backwards (from last element to first element). (*)
Search for a specific character or String inside of the String. (*)
Parse the String. (*)
You don't use a FOR loop with Strings
Incorrect Incorrect. Refer to Section 3 Lesson 1.
10. 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 Incorrect. Refer to Section 3 Lesson 1.
11. Which of the following methods are StringBuilder methods? Mark for Review
(1) Points
append
delete
insert
replace
All of the above. (*)
Incorrect Incorrect. Refer to Section 3 Lesson 1.
12. 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
13 (*)
10
9
12
Incorrect Incorrect. Refer to Section 3 Lesson 3.
13. 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.
14. 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 Incorrect. Refer to Section 3 Lesson 3.
15. The base case condition can work with a constant or variable.
True or false? Mark for Review
(1) Points
True (*)
False
Incorrect Incorrect. Refer to Section 3 Lesson 3.
Tidak ada komentar:
Posting Komentar