String Methods Quiz

By Mickey Arnold
Last updated 10 months ago
21 Questions

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.length() );

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(4) );

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.indexOf( "dog" ) );

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( "cat" ) );

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("-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";

System.out.print( one.length());

System.out.print( two.length());

System.out.print( three.length());

System.out.print( one.substring(0,4) );

System.out.print( one.substring(5) );

System.out.print( one.substring(9) );

System.out.print( one.indexOf( "c" ) );

System.out.print( one.indexOf( "sci" ) );

System.out.print( one.indexOf( "code" ) );

System.out.print( one.lastIndexOf( "c" ) );

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///
}