Jumat, 14 Juli 2017

OJP SECTION QUIZ 2

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.

OJP QUIZ SECTION

1.  Which of the following correctly defines a StringBuilder?  Mark for Review
(1) Points
   
 
 A class that represents a string-like object. (*)
 
 A method that adds characters to a string.
 
 There is no such thing as a StringBuilder in Java.
 
 A class inside the java.util.regex package.
   
  
Incorrect  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 Three)  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  Incorrect. Refer to Section 3 Lesson 1.
   
  3.  What is the result from the following code?
public class Test {
    public static void main(String[] args) {
     String str = "91204";
     str += 23;
     System.out.print(str);
    }
}  Mark for Review
(1) Points
   
 
 91204
 
 Compile fails.
 
 91227
 
 9120423 (*)
 
 23
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 1.
   
  4.  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.
   
  
Correct  Correct
   
  5.  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 regular expression symbol that represents any character.
 
 A class in the java.util.regex package that stores the format of a regular expression.
 
 A method of dividing a string into a set of sub-strings.
   
  
Incorrect  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
   
  
Correct  Correct
   
  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.contains(".");
 
 return str.matches(".?"); (*)
 
 if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
 
 return str.matches("[a-z]*");
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 2.
   
  8.  Which of the following correctly defines Pattern?  Mark for Review
(1) Points
   
 
 A method of dividing a string into a set of sub-strings.
 
 A regular expression symbol that represents any character.
 
 A class in the java.util.regex package that stores matches.
 
 A class in the java.util.regex package that stores the format of a regular expression. (*)
   
  
Correct  Correct
   
  9.  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.
   
  10.  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.
11.  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.
   
  12.  Forward thinking helps when creating linear recursive methods.
True or false?  Mark for Review
(1) Points
   
 
 True
 
 False (*)
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 3.
   
  13.  A base case can handle nested conditions.
True or false?  Mark for Review
(1) Points
   
 
 True (*)
 
 False
   
  
Correct  Correct
   
  14.  A linear recursive method can call how many copies of itself?  Mark for Review
(1) Points
   
 
 1 (*)
 
 2 or more
 
 None
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 3.
   
  15.  Which two statements can create an instance of an array? (Choose Two)  Mark for Review
(1) Points
   
   (Choose all correct answers)
   
 
 Object oa = new double[5]; (*)
 
 char[] ca = "java";
 
 int[] ia = new int [5]; (*)
 
 int ia[][] = (1,2,3) (4,5,6);
 
 double da = new double [5];
   
  
Incorrect  Incorrect. Refer to Section 3 Lesson 3.