Computer Application String Jobsheet
Topic covered String Handling
Q1. Find the output:
Consider String str = "Java Programming";
1. char ch = [Link](2);
[Link](ch);
2. String str1 = "Java";
if ([Link]("J"))
[Link]("Start Same");
if ([Link]("T"))
[Link]("End Same");
3. [Link]([Link]("a"));
4. [Link]([Link]("m"));
5. [Link]([Link]("a"));
6. [Link]([Link]("m"));
7. String str2 = [Link](5);
[Link](str2); [Link]([Link](5, 9));
8. [Link]([Link]('a', '9'));
9. [Link]([Link](“Java”);
10. [Link]([Link](“JAVA”);
Q2. Select the correct option and state the reason:
1. String s = "Java String Quiz";
[Link]([Link]([Link]().length()));
a) Compile Error b)z c)Z d) no output
2. String x = "abc";
String y = "abc";
[Link](y);
[Link](x);
a) abcabc b)abc c)Compile error d) no output
3. String x = "abc";
String y = "abc";
x=[Link](y);
[Link](x);
a) abcabc b)abc c)error d) no output
[Link] str2=”Rama”,str1=”SITHA”;
[Link]([Link](0)>[Link](0));
a) true b) false c)Compile Error d) 0
5. String str1=”Kolkata”.replace(‘k’,’a’);
a) the first occurrence of k is replaced by a b) all the character k is replaced by a
c) all the character a is replaced by k d) Compile Error
6. String s1=”s1=”+”123”+”456”;
String s2=”s2=”+(123+456);
[Link](s1+” , “+s2);
a)s1=123456, s2=579 b)s1=123456, s2=123456
c)s1=579, s2=579 d)None of the above
[Link] the following Question:
i. In which package is String class present?
ii. Which method of class String is used to obtain length of String object?
iii. Which method of class String is used to extract a single character from a
String object?
iv. Which method of class String is used to check weather a given object starts
with a particular string literal?
v. Which method of class String is used to extract a substring from a String
object?
vi. Which method of class String is used to remove leading and trailing
whitespaces?
vii. Write a java statement to print the output as ? for the following string:
(hint:Write the index number of character)
a. String JavaStr = "Are you a Java expert? Yes, you are.";
viii. What is the value returned by the method call [Link](9)?
a. String Java = "Are you a Java expert? Yes, you are.";
ix. What will be the output:
String Str1 = " Java ";
String Str2 = " is ";
String Str3 = " awesome .";
String StrResult = [Link]() + Str2 + [Link]();
a. [Link](StrResult);
x. What is the output:
a. String str1 = "How are you?";
b. String str2 = [Link](5, 7);
c. [Link](str2);
xi. Differentiate between
a. equals() and equalsIgnoreCase()
b. == and equals()
c. compareTo() and equals()
d. + and concat
e. charAt() and indexOf()
f. startsWith() and endsWith()