Page 437 - CA_Blue( J )_Class10
P. 437

13.  Which method is used to find the length of a string in Java?
                       a.  size()                                      b.  len()
                       c.  getLength()                                 d.  length()
                   14.  What will be the output of the following code?
                       String s = "Java";

                       System.out.println(s.charAt(1)+1);
                       a.  97                                          b.  98
                       c.  99                                          d.  Compilation error
                   15.  Which of the following methods can be used to compare two strings in Java, ignoring case differences?
                       a.  compareTo()                                 b.  equals()
                       c.  equalsIgnoreCase()                          d.  contentEquals()

                  Answers
                    1. a      2. c      3. a      4. a      5. c   6. d   7. a   8. b   9. c    10. b
                  11. b    12. b   13. d    14. b   15. c

                 B.  Fill in the blanks.
                    1.  Consider the following code:
                       String str= "Java is a High-Level Language";
                       This type of String declaration is known as …………….
                    2.  The ………………… method returns the index value of the first occurrence of the character present in the String object.
                    3.  The ………………… method combines two strings together.
                    4.  The ………………… method returns true if both the strings are equal otherwise returns false.
                    5.  The ………………… method is used to find the length of the string array.
                    6.  An array of strings is known as ………………….
                    7.  The ………………… method converts the String to small letters.
                    8.  The ………………… method converts the String to capital letters.
                    9.  The String class is available under the ………………… package of Java Class Library (JCL).
                   10.  A ………………… is a part of a string.
                  Answers
                     1.  implicit declaration   2.  indexOf(char)   3.  concat()   4.  equals()   5.  length()   6.  String array
                     7.  toLowerCase()   8.  toUpperCase()   9.  java.lang   10.  substring



                 C.  Answer the following questions:
                    1.  Using string method, returns the index of the last character ch from the word wd.
                   Ans.  int i= wd.lastIndexOf(ch);
                    2.  Write a statement to replace a character ch1 with character ch2 in the sentence str.
                   Ans.  String str1=str.replace(ch1, ch2);
                    3.  What is the output of the following statements?
                       (i)  System.out.println("four: " + 4 + 2);  (ii)  System.out.println("four: " + (2 + 2));
                       (iii)  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));



                                                                                                                       435
                                                                                                       String Handling  435
   432   433   434   435   436   437   438   439   440   441   442