String Work Sheet

Last updated over 1 year ago
44 questions
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 = "sambenwilearethebest";
String two = "09876543210";
String three = "02 13 97 68 45 0";
1

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

1

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

1

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

1

System.out.print( one.charAt( 2 ) );

1

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

1

System.out.print(one.charAt(one.length()-1));

1

System.out.print( one.charAt( 6 ) );

1

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

1

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

1

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

1

System.out.print( one.substring(2,7));

1

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

1

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

1

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

1

System.out.print( two.indexOf("54"));

1

System.out.print( two.indexOf("24"));

1

System.out.print( one.indexOf( 'w' ));

1

System.out.print( two.indexOf( 'b' ));

1

System.out.print( two.indexOf( 's' ));

1

System.out.print( three.indexOf("45"));

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 sam = "hey there";
String ben = "hey thar";
1

out.println( sam.indexOf('h') );

1

out.println( sam.indexOf('7') );

1

out.println( ben.indexOf('a') );

1

out.println( ben.indexOf( 'y' ));

1

out.println( sam.indexOf("ey") );

1

out.println( ben.indexOf("ar") );

1

out.println( sam.charAt(3) );

1

out.println( sam.charAt(0) );

1

out.println( sam.substring(3,6) );

1

out.println( sam.substring(0,4) );

1

out.println( sam.equals(ben) );

1

out.println( sam.compareTo(ben) );

1

out.println( ben.compareTo(sam) );

1

out.println( ben.compareTo("abc") );

1

out.println( ben.replaceAll("e","#") );

1

out.println( ben.replaceAll("#","*") );

1

out.println( ben.length() );

1

out.println( sam.length() );

1

out.println( sam.charAt(20) );

1

To which package does String belong?

1

Explain method String substring(int beginIndex, int endIndex) and what it returns?

1

Explain method int indexOf(String str) and what it returns?

1

Explain method int length() and what purpose it serves?

1

How many indexOf methods does the String have? Define the term overloading. Is the String indexOf method overloaded?