WorksheetsString
Total questions: 10
Worksheet time: 10mins
What is the output of the code segment below?
String s = "dogfood";
System.out.prinln( s.substring(0, 3));
food
dog
ood
dfo
What is the output of the code segment below?
String s = "dogfood";
System.out.println( s.length() );
3
7
6
5
4
What is the output of the code segment below?
String s = "dogfood";
System.out.println( s.substring(2, 5) );
food
dog
dogs
ood
gfo
What is the output of the code segment below?
String s = "dogfood";
System.out.println( s.substring(4) );
food
dog
dogs
ood
dr who
What is the output of the code segment below?
String s = "dogfood";
System.out.println( s.substring(3).length() );
3
2
-1
4
5
What is the output of the code segment below?
String s = "dogfood";
System.out.println( s.indexOf( "dog" ) );
3
2
-1
4
0
What is the output of the code segment below?
String s = "dogfood";
System.out.println( s.indexOf( "oo" ) );
3
2
-1
4
0
What is the output of the code segment below?
String s = "dogfood";
System.out.println( s.indexOf( "cat" ) );
3
2
-1
4
0
What is the output of the code segment below?
String s = "abac-adae-bfbg-bhbi";
int index = s.indexOf( "ae" );
System.out.println( index );
8
-1
6
7
there is no output due to syntax error.
What is the output of the code segment below?
String s = "abac-adae-bfbg-bhbi";
int index = s.indexOf( "-b" );
System.out.println( s.substring( index ) );
abac-adae-bfbg-bhbi
-bfbg-bhbi
bfbg-bhbi
bhbi
there is no output.
