1.
Give the output of the following program fragment:
String s=new String(“He went to the market”);
String r;
r=[Link](“went”,“is going”);
[Link](r);
2. Give the output of the following program fragment:
String s=“String”;
int a=12,b=45;
[Link](s+a+b);
[Link](a+s+b);
[Link](a+b+s);
3. Give the output of the following program fragment:
String s=“india”,s1=“IndIA”,s2=s;
[Link]([Link](s1));
[Link]([Link](s1));
[Link](s2==s);
[Link]([Link]()==[Link]());
[Link]([Link](“IN”.toLowerCase()));
[Link]([Link](“iA”.toUpperCase()));
4. What do the following functions return for:
String x =“hello”;
String y =“world”
[Link](x + y);
[Link]([Link]();
[Link]([Link](3));
[Link]([Link](y));
5. What is the output of the following:
(i) [Link] (“four :” + 4 + 2);
[Link] (“four :”+(2+2));
(ii) String S1 = “Hi”;
String S2 = “Hi”;
String S3 = “there”;
String S4 = “HI”;
[Link](S1 + “equals” + S2 + “→” + [Link](S2));
[Link](S1 + “equals” + S3 + “→” + [Link](S3));
[Link](S1 + “equals” + S4 + “→” + [Link](S4));
[Link](S1 + “equalsIgnoreCase” +S4 + “→” + [Link](S4));
6. If, String x = “Computer”;
String y = “Applications”;
What do the following functions return for:
(i) [Link]([Link](1,5));
(ii) System [Link]([Link]([Link](4)));
(iii) [Link](y+[Link](5));
(iv) [Link]([Link](y));
7. What will be the output for the following program segment?
String s = new String(“abc”);
[Link]([Link]());
8. What will be the output of the following code?
char x = ‘A’; int m;
m=(x= =’a’) ? ‘A’ : ‘a’;
[Link](“m=”+m);
9. Write statements to show how finding the length of a character array and char[] differs
from
finding the length of a String object str.
10. Write a statement each to perform the following task on a string:
(i) Find and display the position of the last space in a string s.
(ii) Convert a number stored in a string variable x to double data type
11. Write a statement each to perform the following task on a string:
(i) Extract the second last character of a word stored in the variable wd.
(ii) Check if the second character of a string str is in uppercase
12. Give the output of the following string functions:
(i) “ACHIEVEMENT”.replace(‘E’,‘A’)
(ii) “DEDICATE”.compareTo(“DEVOTE”)
13. Consider the following String array and give the output:
String arr[]={“DELHI”, “CHENNAI”, “MUMBAI”, “LUCKNOW”, “JAIPUR”};
[Link](arr[0].length()>arr[3].length());
[Link](arr[4].substring(0,3));
14. String x[] = {“SAMSUMG”, “NOKIA”, “SONY”, “MICROMAX”, “BLACKBERRY”};
Give the output of the following statements:
(i) [Link](x[1]);
(ii) [Link](x[3].length());
15. Write the output for the following:
String s=“Today is Test”;
[Link]([Link](‘T’));
[Link]([Link](0,7)+“ ”+“Holiday”);
16. Give the ouput of the following string functions:
(i) “MISSISSIPPI”.indexOf(‘S’)+“MISSISSIPPI”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)
17. State the output of the following program segment when executed:
String a = “Smartphone”, b = “Graphic Art”;
String h = [Link](2, 5);
String k = [Link](8).toUpperCase();
[Link](h);
[Link]([Link](h));
18. State the output of the following program segment:
String str1 = “great”; String str2 = “minds”;
[Link]([Link](0,2).concat([Link](1)));
[Link]((“WH” + ([Link](2).toUpperCase())));
19. State the value of characteristic and mantissa when the following code is executed.
String s = “4.3756”;
int n = [Link](‘.’);
int characteristic = [Link]([Link](0,n));
int mantissa = [Link]([Link](n+1));
20. State the output of the following program segment.
String s = “Examination”;
int n = [Link]();
[Link]([Link]([Link](5, n)));
[Link]([Link](2) == [Link](6));
21. What will the following code output?
String s = “malayalam”;
[Link]([Link](‘m’));
[Link]([Link](‘m’));
22. Give the output of the following:
String n = “Computer Knowledge”;
String m = “Computer Applications”;
[Link]([Link] (0,8).concat([Link](9)));
[Link]([Link](“e”));