String Objective Test For JAVA ICSE Class X
String Objective Test For JAVA ICSE Class X
Q1. Write the Java code to retrieve the index of the first occurrence of the character 'a' in the string str. [1]
Ans:
Q2. Which method is used to remove leading and trailing whitespace from a string in Java? [1]
Ans:
Ans:
Q4. State the return type of the following functions: startsWith(), compareTo() [1]
Ans:
Q5.Write a statement to extract the second last character of a word stored in the variable wd. [1]
Ans:
Ans:
Ans:
Q10. Find the output: String s1= “APPLICATION”, s2= “PROGRAMMING”; [2]
System.out.println( s1.substring(5).concat(s2.substring(s1.indexOf(‘P’),s1.lastIndexOf(‘I’))));
Ans:
System.out.println(st.substring(st.indexOf(‘i’),st.lastIndexOf(‘n’))); Ans:
Q14. Find the output: char ch= ‘b’; String st= “b”; System.out.println(st+Character.toUpperCase(ch)+ ‘a’); [2]
Ans:
Q15. Find the output: String s= “TODAY”; int n=s.length(); System.out.println(s.startsWith(s.substring(2,n))); [2]
Ans:
Q16. Find the output: String s1= “Hello” , s2= “hi”; System.out.println(s1.compareToIgnoreCase(s2)); [2]
Ans:
Q18. Find the output: String n = "Computer Knowledge"; String m = "Computer Applications"; [2]
System.out.println(n.substring(0,8).concat(m.substring(9))); System.out.println(n.endsWith("e"));
Ans:
Q21. Write a statement each to perform the following task on a string [2]