CH 4 Strings
CH 4 Strings
a. System.out.println(s1.substring(0).concat(s2.substring(2)));
b. System.out.println(s2.toUpperCase());
c. System.out.println ("DEDICATE".compareTo("DEVOTE"));
d. System.out.println(arr[0].length() > arr[3].length());
4. 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.ends With(“e”));
5. State the purpose and return data type of the following String functions :
(i) indexOf().
(ii) compareTo().
6. Write the output of the following String methods:
a. "ARTIFICIAL ".indexOf('F' )
b. “ DOG and PUPPY ”. trim().length()
7.
8. Write the difference between length and length() functions.
9. System.out.print(“BEST”); |2]
System.out.println(“OF LUCK”);
10. Write the return data type of the following function.
(i) endsWith( )
(ii) log( )
11. State the difference between == operator and equals ( ) method.
12. What is the value stored in variable res given below :
double res = Math.pow (“345”.indexOf(‘5’), 3);
20. 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));
28. 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));
29. What will be the output when the following code segments are executed ?
(i) String s = “1001”;
int x = Integer. valueOf(s);
double y = Double.valueOf(s);
System.out.println(“x=”+x);
System.out.println(“y=”+y);
System.out.println(“The king said\”Begin at the beginning!\“to me.”);
30. State the values stored in the variables str 1 and str 2
String s1 = “good”; Strings s2 = “world / matters”;
String str 1 = s2. substring (5). replace (‘t’, ‘n’);
String str 2 = s1. concat (str 1);
31. State the output of the following program segment :
String s=“Examination”;
int n=s.length();
System.out.println(s.starts With(s.substring(5,n)));
System.out.println(s.charAt(2)==s.charAt(6));