Twa kɔ nsɛm atitiriw so
Log in
Sign up for FREE
arrow_back
Laabri

String Methods Quiz

star
star
star
star
star
Last updated over 2 years ago
21 Nsɛmmisa
4
4
4
4
4
4
4
4
4
4
20
Asemmisa {{asɛmmisaAhyɛnsode}}
1.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.substring(0,3) );

Asemmisa {{asɛmmisaAhyɛnsode}}
2.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.length() );

Asemmisa {{asɛmmisaAhyɛnsode}}
3.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.substring(2,5) );

Asemmisa {{asɛmmisaAhyɛnsode}}
4.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.substring(4) );

Asemmisa {{asɛmmisaAhyɛnsode}}
5.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.substring(3).length() );

Asemmisa {{asɛmmisaAhyɛnsode}}
6.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.indexOf( "dog" ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
7.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.indexOf( "oo" ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
8.

Consider the following code segment.

String s = "dogfood";

System.out.println( s.indexOf( "cat" ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
9.

What is output by the code below?

String s = "abac-adae-bfbg-bhbi";

int index = s.indexOf("ae");

System.out.println( index );

Asemmisa {{asɛmmisaAhyɛnsode}}
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
Asemmisa {{asɛmmisaAhyɛnsode}}
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///

}

Asemmisa {{asɛmmisaAhyɛnsode}}
11.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
12.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
13.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
14.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
15.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
16.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
17.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
18.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
19.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
20.

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