Page 438 - CA_Blue( J )_Class10
P. 438

Ans.  (i)  four: 42                                 (ii)  four: 4
                     (iii)  Hi equals Hi -> true
                        Hi equals there -> false
                        Hi equals HI > false
                        Hi equalsIgnoreCase HI -> true
                  4.  Write the difference between:
                    a.  concat() and “+” operation on string
                Ans.
                                    concat()                      “ + ” operation on string
                     String function() joining two strings  Operator to join two strings
                     Example Sting st1="India",st2="Kolkata";  Example Sting st1="India”,st2="Kolkata";
                     System.out.println(st1.concat(st2));  System.out.println(st1+st2);
                     Ans: IndiaKolkata                     Ans: IndiaKolkata

                    b.  equals() and equalsIgnoreCase()
                Ans.
                                    equals()                        equalsIgnoreCase()
                     This function is case-sensitive.      This function is non case-sensitive
                     Example Sting st1="India",st2="INDIA";  Example Sting st1="India",st2="INDIA";
                     System.out.println(st1.equals(st2));  System.out.println(st1.
                     Ans: false                            equalsIgnoreCase(st2));
                                                           Ans: true

                    c.  toUpperCase() and toLowerCase()
                Ans.
                                 toUpperCase()                        toLowerCase()
                     Converts the small letters to capital letters.  Converts the capital letters to small letters
                     Example Sting st1="India";            Example Sting st1="India";
                     System.out.println(st1.toUpperCase());  System.out.println(st1.toLowerCase());
                     Ans: INDIA                            Ans: india
                    d.  == operator and equals() method
                Ans.               == operator                           equals()

                     Checks whether both the characters are equal  Checks whether both the strings are equal
                     or not.                               or not.
                     Example: char ch1='A' , ch2='a';      Example: Sting st1= "India", st2="INDIA";
                     System.out.println(ch1==ch2);         System.out.println(st1.equals(st2));

                     Ans: true                             Ans: false
                  5.  If String x = "Computer";
                      String y = "Applications";
                    What is the output of the following statements?
                    (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));
                Ans.  (i)  ompu                                     (ii)  4
                     (iii) Applicationster                         (iv)  False
                  6.  If array[] = {"India","America","England","Sri Lanka", "Bangladesh"};
                    (i)  What is the length of the array?           (ii)  What is the value of array[2]?
                     (iii) What is the value of array[2].length()?
                Ans.  (i)  5                                        (ii)  England
                     (iii) 7

                436436  Touchpad Computer Applications-X
   433   434   435   436   437   438   439   440   441   442   443