String Methods Quiz
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
21 Questions
4 points
4
Question 1
1.
Consider the following code segment.String s = "dogfood";System.out.println( s.substring(0,3) );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(0,3) );
4 points
4
Question 2
2.
Consider the following code segment.String s = "dogfood";System.out.println( s.length() );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.length() );
4 points
4
Question 3
3.
Consider the following code segment.String s = "dogfood";System.out.println( s.substring(2,5) );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(2,5) );
4 points
4
Question 4
4.
Consider the following code segment.String s = "dogfood";System.out.println( s.substring(4) );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(4) );
4 points
4
Question 5
5.
Consider the following code segment.String s = "dogfood";System.out.println( s.substring(3).length() );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(3).length() );
4 points
4
Question 6
6.
Consider the following code segment.String s = "dogfood";System.out.println( s.indexOf( "dog" ) );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "dog" ) );
4 points
4
Question 7
7.
Consider the following code segment.String s = "dogfood";System.out.println( s.indexOf( "oo" ) );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "oo" ) );
4 points
4
Question 8
8.
Consider the following code segment.String s = "dogfood";System.out.println( s.indexOf( "cat" ) );
Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "cat" ) );
4 points
4
Question 9
9.
What is output by the code below?String s = "abac-adae-bfbg-bhbi";int index = s.indexOf("ae");System.out.println( index );
What is output by the code below?
String s = "abac-adae-bfbg-bhbi";
int index = s.indexOf("ae");
System.out.println( index );
4 points
4
Question 10
10.
What is output by the code below?String s = "abac-adae-bfbg-bhbi";int index = s.indexOf("-b");System.out.println(s.substring(index));
What is output by the code below?
String s = "abac-adae-bfbg-bhbi";
int index = s.indexOf("-b");
System.out.println(s.substring(index));
DIRECTIONS : Fill in each blank with the correct answer/output. Assume each statement happens in order and that one statement may affect the next statement.
String one = "apcomputersciencerocks";
String two = "098765210AB#";
String three = "02 13 998 45 0";
4 points
4
Question 11
11.
System.out.print( one.length());
System.out.print( one.length());
4 points
4
Question 12
12.
System.out.print( two.length());
System.out.print( two.length());
4 points
4
Question 13
13.
System.out.print( three.length());
System.out.print( three.length());
4 points
4
Question 14
14.
System.out.print( one.substring(0,4) );
System.out.print( one.substring(0,4) );
4 points
4
Question 15
15.
System.out.print( one.substring(5) );
System.out.print( one.substring(5) );
4 points
4
Question 16
16.
System.out.print( one.substring(9) );
System.out.print( one.substring(9) );
4 points
4
Question 17
17.
System.out.print( one.indexOf( "c" ) );
System.out.print( one.indexOf( "c" ) );
4 points
4
Question 18
18.
System.out.print( one.indexOf( "sci" ) );
System.out.print( one.indexOf( "sci" ) );
4 points
4
Question 19
19.
System.out.print( one.indexOf( "code" ) );
System.out.print( one.indexOf( "code" ) );
4 points
4
Question 20
20.
System.out.print( one.lastIndexOf( "c" ) );
System.out.print( one.lastIndexOf( "c" ) );
20 points
20
Question 21
21.
DIRECTIONS : Write a return method named wow that return the last ½ of a string plus the word "FUN". The call wow("compze") returns "pzeFUN"
public static String wow( String s ){ ///your code goes here///}
DIRECTIONS : Write a return method named wow that return the last ½ of a string plus the word "FUN". The call wow("compze") returns "pzeFUN"
public static String wow( String s ){
///your code goes here///
}