0% found this document useful (0 votes)
46 views

StringManipulation

Uploaded by

tapaskumarmahato
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

StringManipulation

Uploaded by

tapaskumarmahato
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Give the output of the following program fragment:


String s=new String(“He went to the market”);
String r;
r=s.replace(“went”,“is going”);
System.out.println(r);
2. Give the output of the following program fragment:
String s=“String”;
int a=12,b=45;
System.out.println(s+a+b);
System.out.println(a+s+b);
System.out.println(a+b+s);
3. Give the output of the following program fragment:
String s=“india”,s1=“IndIA”,s2=s;
System.out.println(s.equals(s1));
System.out.println(s.equalsIgnoreCase(s1));
System.out.println(s2==s);
System.out.println(s.toUpperCase()==s1.toUpperCase());
System.out.println(s.startsWith(“IN”.toLowerCase()));
System.out.println(s1.endsWith(“iA”.toUpperCase()));
4. What do the following functions return for:
String x =“hello”;
String y =“world”
System.out.println(x + y);
System.out.println(x.length();
System.out.println(x.charAt(3));
System.out.println(x.equals(y));
5. What is the output of the following:
(i) System.out.println (“four :” + 4 + 2);
System.out.println (“four :”+(2+2));
(ii) String S1 = “Hi”;
String S2 = “Hi”;
String S3 = “there”;
String S4 = “HI”;
System.out.println(S1 + “equals” + S2 + “→” + S1.equals(S2));
System.out.println(S1 + “equals” + S3 + “→” + S1.equals(S3));
System.out.println(S1 + “equals” + S4 + “→” + S1.equals(S4));
System.out.println(S1 + “equalsIgnoreCase” +S4 + “→” + S1.equalsIgnoreCase(S4));
6. If, String x = “Computer”;
String y = “Applications”;
What do the following functions return for:
(i) System.out.println(x.substring(1,5));
(ii) System out.println(x.indexOf(x.charAt(4)));
(iii) System.out.println(y+x.substring(5));
(iv) System.out.println(x.equals(y));
7. What will be the output for the following program segment?
String s = new String(“abc”);
System.out.println(s.toUpperCase());
8. What will be the output of the following code?
char x = ‘A’; int m;
m=(x= =’a’) ? ‘A’ : ‘a’;
System.out.println(“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”};
System.out.println(arr[0].length()>arr[3].length());
System.out.print(arr[4].substring(0,3));

14. String x[] = {“SAMSUMG”, “NOKIA”, “SONY”, “MICROMAX”, “BLACKBERRY”};


Give the output of the following statements:
(i) System.out.println(x[1]);
(ii) System.out.println(x[3].length());
15. Write the output for the following:
String s=“Today is Test”;
System.out.println(s.indexOf(‘T’));
System.out.println(s.substring(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 = a.substring(2, 5);
String k = b.substring(8).toUpperCase();
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));
18. State the output of the following program segment:
String str1 = “great”; String str2 = “minds”;
System.out.println(strl.substring(0,2).concat(str2.substring(1)));
System.out.println((“WH” + (strl.substring(2).toUpperCase())));
19. State the value of characteristic and mantissa when the following code is executed.
String s = “4.3756”;
int n = s.indexOf(‘.’);
int characteristic = Integer.parseInt(s.substring(0,n));
int mantissa = Integer.valueOf(s.substring(n+1));
20. State the output of the following program segment.
String s = “Examination”;
int n = s.length();
System.out.println(s.startsWith(s.substring(5, n)));
System.out.println(s.charAt(2) == s.charAt(6));
21. What will the following code output?
String s = “malayalam”;
System.out.println(s.indexOf(‘m’));
System.out.println(s.lastIndexOf(‘m’));
22. Give the output of the following:
String n = “Computer Knowledge”;
String m = “Computer Applications”;
System.out.println(n.substring (0,8).concat(m.substring(9)));
System.out.println(n.endsWith(“e”));

You might also like