Page 478 - CA_Blue( J )_Class10
P. 478

7              String str="",cap="",small="",digit="";       //declaration of variable
                 8              int len,i,capc=0,smallc=0,digitc=0;

                 9              char ch;
                10              System.out.print("Enter a sentence : ");

                11              str = sc.nextLine();                    //Enter of word
                12              len = str.length();                    //Length of word

                13              for (i = 0; i < len; i++)
                14              {

                15                  ch = str.charAt(i);                    //Extraction of character
                16                  if (Character.isUpperCase(ch))   // checking for capital letters

                17                  {
                18                      cap = cap + " " + ch;
                19                      capc++;

                20                  }

                21                  if (Character.isLowerCase(ch))   // checking for small letters
                22                  {
                23                      small = small + " " + ch;

                24                      smallc++;
                25                  }

                26                  if (Character.isDigit(ch))   // checking for digits
                27                  {

                28                      digit = digit + " " + ch;
                29                      digitc++;

                30                  }
                31              }

                32              System.out.println("The Uppercase letters are :"+ cap + " and total number
                           : " + capc);
                33              System.out.println("The Lowercase   letters are :"+ small + " and total
                           number : " + smallc);
                34      System.out.println("The digits are :"+ digit + " and total number : " + digitc);

                35      }
                36      }

              Output
              Enter a sentence : The car number is WB02A 2546
              The Uppercase letters are : T W B A and total number : 4
              The Lowercase letters are : h e c a r n u m b e r i s and total number : 13
              The digits are : 0 2 2 5 4 6 and total number : 6


                476476  Touchpad Computer Applications-X
   473   474   475   476   477   478   479   480   481   482   483