String Methods Quiz
star
star
star
star
star
Last updated over 1 year ago
21 questions
4
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
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
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
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
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
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
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
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
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
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
System.out.print( one.length());
System.out.print( one.length());
4
System.out.print( two.length());
System.out.print( two.length());
4
System.out.print( three.length());
System.out.print( three.length());
4
System.out.print( one.substring(0,4) );
System.out.print( one.substring(0,4) );
4
System.out.print( one.substring(5) );
System.out.print( one.substring(5) );
4
System.out.print( one.substring(9) );
System.out.print( one.substring(9) );
4
System.out.print( one.indexOf( "c" ) );
System.out.print( one.indexOf( "c" ) );
4
System.out.print( one.indexOf( "sci" ) );
System.out.print( one.indexOf( "sci" ) );
4
System.out.print( one.indexOf( "code" ) );
System.out.print( one.indexOf( "code" ) );
4
System.out.print( one.lastIndexOf( "c" ) );
System.out.print( one.lastIndexOf( "c" ) );
20
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///
}