Log in
Sign up for FREE
arrow_back
Library

String Methods Quiz

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

Question 2
2.

Question 3
3.

Question 4
4.

Question 5
5.

Question 6
6.

Question 7
7.

Question 8
8.

Question 9
9.

Question 10
10.

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

Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(0,3) );
ood
dog
dogs
gfo
food
Consider the following code segment.
String s = "dogfood";
System.out.println( s.length() );
7
6
5
4
3
Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(2,5) );
food
dog
dogs
gfo
ood
Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(4) );
ood
dog
food
dogs
dr who
Consider the following code segment.
String s = "dogfood";
System.out.println( s.substring(3).length() );
4
-1
2
3
5
Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "dog" ) );
4
2
0
3
-1
Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "oo" ) );
3
2
0
4
-1
Consider the following code segment.
String s = "dogfood";
System.out.println( s.indexOf( "cat" ) );
-1
4
3
0
2
What is output by the code below?
String s = "abac-adae-bfbg-bhbi";
int index = s.indexOf("ae");
System.out.println( index );
there is no output due to a syntax error
8
-1
6
7
What is output by the code below?
String s = "abac-adae-bfbg-bhbi";
int index = s.indexOf("-b");
System.out.println(s.substring(index));
there is no output
bfbg-bhbi
-bfbg-bhbi
abac-adae-bfbg-bhbi
bhbi
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";
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" ) );