You are on page 1of 4

PRACTICE WORKSHEET 6 CHAPTER : STRINGS

Q1. Write the output of the following given String s = “hippocampus“

1. s.lastIndexOf(‘p’);
a. 2
b. 8
c. 9

2. s.substring(0,4).charAt(2);
a. h
b. i
c. p

3. s.substring(3,5).concat(s.substring(0,2));
a. pohi
b. pochip
c. pohic

4. s.compareTo(“hippo”);
a. -1
b. 6
c. -6

5. s.indexOf(s.charAt(8));
a. 2
b. 3
c. 8

Q2. Write the output of the following given String s = “Committee”

1. Character.isUpperCase(s.charAt(3))
a. true
b. false
c. M

2. s.substring( s.indexOf(‘m’) , s.indexOf(t,6) )


a.mmit
b.mmi
c.mmitt

3. s.equals(“committee”);
a. true
b. false
c. -32

4. s.indexOf(‘m’) + s.lastIndexOf(‘m’)
a. 5
SHAILESH MANJREKAR – 98194 98104
b. 7
c. mM
5. s = “ “ + s + “ “;
System.out.println(s.length() );
s = s.trim();
System.out.println(s.length());

a. 11
9

b. 11
11

c. 9 11

Q3. Choose the correct option.

1.The return type of compareTo() function is


a. boolean
b. int
c. char

2. The function equalsIgnoreCase() returns true even if the cases are different
a. true
b. false
c. none

3. The String class is present in ______ package


a. util
b. lang
c. io

4. The output of
s=” computer applications “
System.out.println(s.trim());
a. ”computer applications “
b. ”computerapplications”
c. ” computer applications “

5. What is the output of the following :


“Missisippi”.compareTo(“Missisippj”);
a. 1
b. -1
c. 0

SHAILESH MANJREKAR – 98194 98104


Q4. Write the output of the following given String s = “Elements”:

1. s.substring(0,4).toUpperCase()
a. ELE
b. ELEM
c. LEME

2. s.substring(3,5).concat(s.substring(5))
a. ments
b.mennts
c. ment

3. s.equalsIgnoreCase(“Element”)
a. true
b. false
c. 0

4. s.startsWith(‘e’)
a. true
b. false
c. StringIndexOutOfBoundsException

5. s.substring(2,5).endsWith(‘e’)
a. true
b. false
c. none

Q5. Answer the following questions

1. Write the memory in bytes that the following strings will occupy
a. “Dorem@\non”
b. “1234@onetwothreefour”
c. “old\t\”man\”on the road’s”

2. Trace errors in the following statements


a. char a = S.indexOf(‘a’);
b. int pos = S.lastIndexOf(‘a’,3);
c. int a = S1.equals(S2);
d. char c = S.charAt(5,3)
e. double l = “99.55”.length;

SHAILESH MANJREKAR – 98194 98104


3. Given the String S=”Institutional”
Write single line java statement to create each of the following string with built-in String functions
a. tution
b. Insnal
c. TITUTI

4. Fill in the blanks to complete the following program :


The function below checks if the emailid passed is valid (contains @ and also . (dot) and returns true or false
accordingly. Fill in the blanks to complete the program

public static _________ checkEmail (String email)


{
if (_____________ || _______________ )
return false;
else
return true;
}

5. Write the output of the following String s=” $h!v3rs”

1. 2. 3.
for (i=0; i<S.length(); i++) for (int i=2; i<s.indexOf(‘r’); i++) int count = 2;
{ System.out.println(S1.charAt(i- while ( count < s.length()-2 )
char ch = S.charAt(i); 1)); {
if ( System.out.println(s.charAt(count+1);
Character.isDigit(ch)==false) count++;
System.out.println(ch); }
}

Q5. Programs

1. Write a program which inputs a String and counts the number of vowels present in the string.

2. Write a program which inputs a String and check if the String is palindrome. A palindrome String is the one which
when reversed gives the same word again, eg : MOM.

3. Write a program to input 2 Strings. Covert the strings to uppercase and join them to create a new String. Also
compare the length of the two strings and print the string with a smaller length. Print EQUAL if the length of the 2
strings is equal.

SHAILESH MANJREKAR – 98194 98104

You might also like