Log in
Sign up for FREE
arrow_back
Library

String Methods Quiz

star
star
star
star
star
Last updated almost 2 years ago
21 questions
4
4
4
4
4
4
4
4
4
4
20
Question 1
1.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(0,3) );

Question 2
2.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.length() );

Question 3
3.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(2,5) );

Question 4
4.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(4) );

Question 5
5.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(3).length() );

Question 6
6.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "dog" ) );

Question 7
7.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "oo" ) );

Question 8
8.

Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "cat" ) );

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

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

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

Question 11
11.

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

Question 12
12.

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

Question 13
13.

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

Question 14
14.

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

Question 15
15.

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

Question 16
16.

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

Question 17
17.

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

Question 18
18.

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

Question 19
19.

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

Question 20
20.

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