Font size
WorksheetsJAVA string-CS1
Total questions: 20
Worksheet time: 11mins
String s ="I like it";
int len = "s.length();
What is the value of len?
8
7
9
6
String s="my school";
int x = s.indexOf("c");
What is the value of x?
1
2
4
3
String s1="whatever";
String s2 = s1.substring(1,4);
What is the value of s2?
"hate"
"hat"
"whate"
"what"
String s = "cute dog";
System.out.print(s.substring(6));
What is the output?
"dog"
"do"
"og"
String s = "nice job".substring(3, 5);
What is the value of s?
e
e job
"ce jo"
Which method would you use to check if two Strings are exactly the same?
equals()
equalsIgnoreCase()
toUpperCase()
toLowerCase()
Which method was used to convert this String: "IT learners are clever" to "IT LEARNERS ARE CLEVER" ?
toUpperCase()
toLowerCase()
equalsIgnoreCase()
compareTo()
Which method was used to convert this String: "Life is TOO SHORT to be BORED" to: "life is too short to be bored" ?
toLowerCase()
toUpperCase()
equals()
equalsIgnoreCase()
Which data type gets returned from length() method in String class?
double
String
int
number
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
What will be the output of below code?
String statement = "Outfit of the day";
System.out.println(statement.Substring(3,6));
it of
tfit
fit
FIT
What is the most appropriate way to check if two Strings are identical?
string1 == string2
string1.equals(string2)
string1.same(string2)
string1.equalsIgnorecase(string2)
What is the correct relation between length and last-index of array?
last-index is always 1 more than the length
last-index is 1 less than the length (but not always)
last-index is always 1 less than the length
last-index is always equal to the length
What is word.length()?
What is word.charAt(7) ?
String word = "A few good men";
What is word.indexOf(“f”)?
2
0
1
3
What is word.substring(3, 7) ?
is this code Good or Bad Java?
String greeting ="hi";
if (greeting == "hello")
{
}
Good
Bad
String s ="Johannesburg"
System.out.print(s.substring(2,5) )
will return:
ohan
han
hann
oha
