Strings Test
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
34 Questions
2.5 points
2.5
Question 1
1.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.substring(4,5) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring(4,5) );
2.5 points
2.5
Question 2
2.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.substring( s.length()-1 ) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring( s.length()-1 ) );
2.5 points
2.5
Question 3
3.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.charAt( s.length()-3 ) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.charAt( s.length()-3 ) );
2.5 points
2.5
Question 4
4.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.charAt(0) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.charAt(0) );
2.5 points
2.5
Question 5
5.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.charAt(5) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.charAt(5) );
2.5 points
2.5
Question 6
6.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.indexOf( "s" ) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.indexOf( "s" ) );
2.5 points
2.5
Question 7
7.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.indexOf( "apluscomp" ) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.indexOf( "apluscomp" ) );
2.5 points
2.5
Question 8
8.
What is output by the code below?
String s = "ishouldofstudied";System.out.println( s.length() );
What is output by the code below?
String s = "ishouldofstudied";
System.out.println( s.length() );
2.5 points
2.5
Question 9
9.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.substring( 6 ) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring( 6 ) );
2.5 points
2.5
Question 10
10.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.indexOf( "b" ) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.indexOf( "b" ) );
2.5 points
2.5
Question 11
11.
What is output by the code below?
String s = "apluscompsci";int x = s.indexOf( "c" );System.out.println( s.substring( x ) );
What is output by the code below?
String s = "apluscompsci";
int x = s.indexOf( "c" );
System.out.println( s.substring( x ) );
2.5 points
2.5
Question 12
12.
What is output by the code below?
int x = "alligator".length() - "crocodile".length();System.out.println( x );
What is output by the code below?
int x = "alligator".length() - "crocodile".length();
System.out.println( x );
2.5 points
2.5
Question 13
13.
What is output by the code below?
int x = "crocodile".length() - "croc".length();System.out.println( x );
What is output by the code below?
int x = "crocodile".length() - "croc".length();
System.out.println( x );
2.5 points
2.5
Question 14
14.
What is output by the code below?
String s = "apluscompsci";System.out.println( s.substring(0,2) );
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring(0,2) );
2.5 points
2.5
Question 15
15.
What is output by the code below?
String s = "apluscompsci";int x = 3;System.out.println( s.substring(x,x+1) );
What is output by the code below?
String s = "apluscompsci";
int x = 3;
System.out.println( s.substring(x,x+1) );
2.5 points
2.5
Question 16
16.
What is output by the code below?
String s = "dog";String r = "dog ";System.out.println( s.equals( r ) );
What is output by the code below?
String s = "dog";
String r = "dog ";
System.out.println( s.equals( r ) );
2.5 points
2.5
Question 17
17.
What is output by the code below?
String s = "dog ";String r = new String("dog");System.out.println( s.equals( r ) );
What is output by the code below?
String s = "dog ";
String r = new String("dog");
System.out.println( s.equals( r ) );
2.5 points
2.5
Question 18
18.
What is output by the code below?
String s = "dog";String r = new String("dog");System.out.println( s != r );
What is output by the code below?
String s = "dog";
String r = new String("dog");
System.out.println( s != r );
2.5 points
2.5
Question 19
19.
What is output by the code below?
String s = "dog";String r = "dog";r = s;s = null;System.out.println( r );
What is output by the code below?
String s = "dog";
String r = "dog";
r = s;
s = null;
System.out.println( r );
2.5 points
2.5
Question 20
20.
What is output by the code below?
String s = "dog";String r = s;s = null;System.out.println( s );
What is output by the code below?
String s = "dog";
String r = s;
s = null;
System.out.println( s );
2.5 points
2.5
Question 21
21.
What is output by the code below?
String s = "Big dog";String r = "A dog";System.out.println( s.compareTo(r) );
What is output by the code below?
String s = "Big dog";
String r = "A dog";
System.out.println( s.compareTo(r) );
2.5 points
2.5
Question 22
22.
What is output by the code below?
String s = "dog";String r = "cog";System.out.println( r.compareTo(s) );
What is output by the code below?
String s = "dog";
String r = "cog";
System.out.println( r.compareTo(s) );
2.5 points
2.5
Question 23
23.
What is output by the code below?
String s = "dodge";String r = "cloths";System.out.println( s.compareTo(r) );
What is output by the code below?
String s = "dodge";
String r = "cloths";
System.out.println( s.compareTo(r) );
2.5 points
2.5
Question 24
24.
What is output by the code below?
String s = "bob";String r = "bod";System.out.println( s.compareTo(r) );
What is output by the code below?
String s = "bob";
String r = "bod";
System.out.println( s.compareTo(r) );
2.5 points
2.5
Question 25
25.
What is output by the code below?
String s = 12;int x = Integer.parseInt( s );System.out.println( x + 3 );
What is output by the code below?
String s = 12;
int x = Integer.parseInt( s );
System.out.println( x + 3 );
2.5 points
2.5
Question 26
26.
What is output by the code below?
String s = "12.7";Double x = Double.parseDouble( s );System.out.println( x + 3 );
What is output by the code below?
String s = "12.7";
Double x = Double.parseDouble( s );
System.out.println( x + 3 );
2.5 points
2.5
Question 27
27.
What is output by the code below?
String s = "12.7";double x = Double.parseDouble( s );System.out.println( x + 3 );
What is output by the code below?
String s = "12.7";
double x = Double.parseDouble( s );
System.out.println( x + 3 );
2.5 points
2.5
Question 28
28.
What is output by the code below?
String s = "12";int x = Integer.parseInt( s );System.out.println( s + x + 3 );
What is output by the code below?
String s = "12";
int x = Integer.parseInt( s );
System.out.println( s + x + 3 );
2.5 points
2.5
Question 29
29.
What is output by the code below?
System.out.println( "12" + 9 + 3 );
What is output by the code below?
System.out.println( "12" + 9 + 3 );
2.5 points
2.5
Question 30
30.
What is returned by the call myst("aplus","aplus")?public boolean myst(String a, String b){ return a.equals( b );}
What is returned by the call myst("aplus","aplus")?
public boolean myst(String a, String b)
{
return a.equals( b );
}
2.5 points
2.5
Question 31
31.
What is returned by the call myst("aplus","aplus")?public boolean myst(String a, String b){ return a == b;}
What is returned by the call myst("aplus","aplus")?
public boolean myst(String a, String b)
{
return a == b;
}
2.5 points
2.5
Question 32
32.
What is returned by the call myst("ana","banana")?public boolean myst(String a, String b){ return b.lastIndexOf(a)!=b.indexOf(a);}
What is returned by the call myst("ana","banana")?
public boolean myst(String a, String b)
{
return b.lastIndexOf(a)!=b.indexOf(a);
}
2.5 points
2.5
Question 33
33.
What is the purpose of myst?public boolean myst(String a, String b){ return b.lastIndexOf(a)!=b.indexOf(a);}
What is the purpose of myst?
public boolean myst(String a, String b)
{
return b.lastIndexOf(a)!=b.indexOf(a);
}
17.5 points
17.5
Question 34
34.
DIRECTIONS : Complete the method below.You will be writing only the go method.The go method should:Two words are sent in to the go method as word1 and letter1You will RETURN an int containing the SUM of both locations for letter1 in word1The answer will be printed in main so you do not need any System.out.printlnShow your work is there if you need it.
public static int go (String word1, char letter1){ //Your code will go here}
DIRECTIONS : Complete the method below.
You will be writing only the go method.
The go method should:
Two words are sent in to the go method as word1 and letter1
You will RETURN an int containing the SUM of both locations for letter1 in word1
The answer will be printed in main so you do not need any System.out.println
Show your work is there if you need it.
public static int go (String word1, char letter1){
//Your code will go here
}