Page 272 - Cs_withBlue_J_C11_Flipbook
P. 272

5.  What does toLowerCase() function do?
                    a.  It converts the lowercase letters to capital letters.   b.  It converts the uppercase letters to lower case letters.
                    c.  It removes the lowercase letters.           d.  None of these
                  6.  The ASCII value of B is ………………… .
                    a.  65                                          b.  98
                    c.  66                                          d.  97
                  7.  The function trim() removes only the spaces between two words in a sentence.
                    a.  True                                        b.  False
                    c.  There is no such function                   d.  True in some conditions
                  8.  The function append() …………………
                    a.  adds a string to the beginning of another string.   b.  concatenates a string at the end of another string.
                    c.  replaces one character with another character.   d.  inserts a string into another string in the middle.
                  9.  The function valueOf(String str) converts ………………… .
                    a.   a string to integer                        b.  an integer to string
                    c.   a string to double                         d.  Both a and c
                 10.  The built-in package(s) used in Java is/are ………………… .
                    a.  java.io                                     b.  java.cal
                    c.  java.lang                                   d.  Both a and c

                 Answers
                  1.  b      2.   a   3.   a    4.   c    5.   b    6.   c    7.   b    8.   b     9.   d     10.  d


              B.  Fill in the blanks:
                  1.  String str= “We are the students of class XI”;
                     This type of declaration is known as ………………… .
                  2.   …………………  class splits the given string into tokens.
                  3.   …………………  is used to return the next token/word from the stringtokenizer object.
                  4.   …………………  returns true if both the strings are equal, else returns false.
                  5.   …………………  method is used to reverse the characters in the given string.

                 Answers
                   1.  Static declaration       2.  StringTokenizer   3.  nextToken()   4.  equals()        5.  reverse()


              C.  Answer the following questions:
                  1.  What is the use of the startsWith() method of the String class?
                Ans.  The startsWith() method checks whether the string in the current string object starts with the string given as a parameter. This
                    function returns a Boolean-type value.
                  2.  Write a program in Java to input a string and print the frequency of the following:
                     a.  capital letters
                     b.  small letters
                     c.  digits
                     d.  special characters.
                Ans.  import java.util.*;
                    class frequency_char
                    {
                        public static void main()
                        {
                            Scanner sc= new Scanner(System.in);
                            String sen;
                            int i, len, cap=0, sma=0, dig=0, spl=0;
                            char ch;
                            System.out.println("Enter a word");

                270270  Touchpad Computer Science-XI
   267   268   269   270   271   272   273   274   275   276   277