Page 446 - CA_Blue( J )_Class10
P. 446

8.  Write statements to show how finding the length of a character array char ch[] differs from finding the length of a String
                    object str.                                                                                   [2013]
                Ans.  For character array : int len = ch.length;
                    For String object str : int len = str.length();
                  9.  State the values stored in the variables str1 and str2:
                    String s1 = "good";
                    String s2 = "world matters";
                    String str1 = s2.substring(5).replace('t', 'n');
                    String str2 = s1.concat(str1);                                                                [2013]
                Ans.  str1 : manners                  str2 : good manners
                 10.  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));                                               [2012]
                Ans.  false
                    true
                 11.  State the data type and values of a and b after the following segment is executed:
                    String s1 = "Computer", s2 = "Applications"
                    a = (s1.compareTo(s2));
                    b = (s1.equals(s2));                                                                          [2012]
                Ans.

                                               Variable           a              b
                                            Data type      int             boolean
                                            Value          2               false
                 12.  What will the following code output:
                    String s = "malayalam";
                    System.out.println(s.indexOf('m'));
                    System.out.println(s.lastIndexOf('m'));                                                       [2012]
                Ans.  0
                    8

                                                            SECTION B

                 13.  Define a class to declare an array to accept and store ten words. Display only those words which begin with the letter 'A' or 'a'
                    and also with the letter 'A' or 'a'.                                                          [2022]
                     EXAMPLE:
                     Input: Hari, Anita, Akash, Amrita, Alina, Devi, Rishab, John, Farha, AMITHA
                     Output:  Anita
                             Amrita
                             Alina
                             AMITHA

                Ans.  import java.util.Scanner;
                      public class Letters
                      {
                          public static void main(String[] args)
                          {
                              String names[] = new String[10];
                              Scanner sc = new Scanner(System.in);
                              int l = names.length;
                              System.out.println("Enter 10 names: ");
                              for (int i = 0; i < l; i++)

                444444  Touchpad Computer Applications-X
   441   442   443   444   445   446   447   448   449   450   451