Log in
Sign up for FREE
arrow_back
Library
Strings Test
By Mickey Arnold
star
star
star
star
star
Share
share
Last updated almost 2 years ago
34 questions
Add this activity
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
17.5
Question 1
1.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring(4,5) );
a
u
p
l
s
Question 2
2.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring( s.length()-1 ) );
s
i
ci
a
p
Question 3
3.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.charAt( s.length()-3 ) );
s
i
a
p
c
Question 4
4.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.charAt(0) );
a
c
p
i
s
Question 5
5.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.charAt(5) );
c
s
p
i
u
Question 6
6.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.indexOf( "s" ) );
3
6
5
4
9
Question 7
7.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.indexOf( "apluscomp" ) );
0
1
2
3
4
Question 8
8.
What is output by the code below?
String s = "ishouldofstudied";
System.out.println( s.length() );
13
12
15
16
14
Question 9
9.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring( 6 ) );
aplus
compsci
sci
o
ompsci
Question 10
10.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.indexOf( "b" ) );
0
1
2
3
-1
Question 11
11.
What is output by the code below?
String s = "apluscompsci";
int x = s.indexOf( "c" );
System.out.println( s.substring( x ) );
compsci
sci
comp
aplus
pluscompsci
Question 12
12.
What is output by the code below?
int x = "alligator".length() - "crocodile".length();
System.out.println( x );
1
-2
2
-1
0
Question 13
13.
What is output by the code below?
int x = "crocodile".length() - "croc".length();
System.out.println( x );
-5
1
-1
0
5
Question 14
14.
What is output by the code below?
String s = "apluscompsci";
System.out.println( s.substring(0,2) );
a
p
pl
ap
us
Question 15
15.
What is output by the code below?
String s = "apluscompsci";
int x = 3;
System.out.println( s.substring(x,x+1) );
s
u
p
0
m
Question 16
16.
What is output by the code below?
String s = "dog";
String r = "dog ";
System.out.println( s.equals( r ) );
1
0
false
true
null
Question 17
17.
What is output by the code below?
String s = "dog ";
String r = new String("dog");
System.out.println( s.equals( r ) );
true
1
null
false
0
Question 18
18.
What is output by the code below?
String s = "dog";
String r = new String("dog");
System.out.println( s != r );
0
false
1
true
null
Question 19
19.
What is output by the code below?
String s = "dog";
String r = "dog";
r = s;
s = null;
System.out.println( r );
true
null
dog
s
false
Question 20
20.
What is output by the code below?
String s = "dog";
String r = s;
s = null;
System.out.println( s );
null
s
true
false
dog
Question 21
21.
What is output by the code below?
String s = "Big dog";
String r = "A dog";
System.out.println( s.compareTo(r) );
1
true
null
0
false
Question 22
22.
What is output by the code below?
String s = "dog";
String r = "cog";
System.out.println( r.compareTo(s) );
-1
3
null
0
1
Question 23
23.
What is output by the code below?
String s = "dodge";
String r = "cloths";
System.
out
.println( s.compareTo(r) );
1
0
null
3
-1
Question 24
24.
What is output by the code below?
String s = "bob";
String r = "bod";
System.out.println( s.compareTo(r) );
1
-2
-5
6
-6
Question 25
25.
What is output by the code below?
String s = 12;
int x = Integer.parseInt( s );
System.out.println( x + 3 );
There is no output due to an error.
0
x3
12
15
Question 26
26.
What is output by the code below?
String s = "12.7";
Double x = Double.
parseDouble
( s );
System.
out
.println( x + 3 );
15.7
There is no output due to an error.
0
x3
12.7
Question 27
27.
What is output by the code below?
String s = "12.7";
double x = Double.parseDouble( s );
System.out.println( x + 3 );
12.7
15.7
0
x3
There is no output due to an error.
Question 28
28.
What is output by the code below?
String s = "12";
int x = Integer.parseInt( s );
System.out.println( s + x + 3 );
There is no output due to an error.
12x3
1215
12123
27
Question 29
29.
What is output by the code below?
System.out.println( "12" + 9 + 3 );
24
null
There is no output due to an error.
1293
1212
Question 30
30.
What is returned by the call
myst("aplus","aplus")
?
public boolean myst(String a, String b)
{
return a.equals( b );
}
1
false
true
null
0
Question 31
31.
What is returned by the call
myst("aplus","aplus")
?
public boolean myst(String a, String b)
{
return a == b;
}
1
null
false
0
true
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);
}
false
0
1
null
true
Question 33
33.
What is the purpose of myst?
public boolean myst(String a, String b)
{
return b.lastIndexOf(a)!=b.indexOf(a);
}
to determine if a occurs exactly once in b
to determine if there are at least two occurrences of a in b.
none of the above
to determine if a is in b
to determine if there are less than two occurrences of a in b
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 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
}
visibility
View drawing