Java program to enter any sentence and calculate the following: a) Total number of digits present in it. b) Total number of small letters and capital letters present in it. c) Total number of alphabets used in it. d) Total number of special character used in it. e) Total number of vowels presents in it. f) Total Number words present in that sentence.

class Sentence
{
  public static void main(String args[])
  {
    String n="O-16, ShivaSagar Apartment, Mumbai, Phone No. 3322430";
    String alp="ABCDEFGH IJKLMNOPQR STUVWXYZ";
    int nd=0,sl=0,cl=0,alpha=0,nv=0,ns=0;
    int l=n.length();
    for(int i=0;i<l;i++)
    {
      char c=n.charAt(i);
      int asc=(int)c;
      if(asc>=48 && asc<=57)
        nd++;
      if(asc>=65 && asc<=90)
        cl++;
      if(asc>=97 && asc<=122)
        sl++;
      if(c==' ')
        ns++;
      if(c=='A'||c=='a'|| c=='E'||c=='e'||c=='I'|| c=='i'||c=='O'|| c=='o'||c=='U'||c=='u')
        nv++;
      // calculating number of alphabets used
      if(Character.isLowerCase(c))
        c=Character.toUpperCase(c);
      int pos=alp.indexOf(c);
      if(pos!=-1)
      {
        alp=alp.replace(c,'0');
        alpha++;
      }
    }
    System.out.println("Sentence is : "+n);
    System.out.println("No. of Digits (0-9) present : "+nd);
    System.out.println("No. of Small Letter : "+sl+" Capital Letter : "+cl);
    System.out.println("No. of Alphabet Used : "+alpha);
    System.out.println("No. of Special Character : "+(l-(nd+sl+cl+ns)));
    System.out.println("No. of Vowels present : "+nv);
    System.out.println("No. of Words present : "+(ns+1));
  }
}

Popular posts from this blog

Priority Scheduling Algorithm Java Program.

Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming).

Implement a class CppArray which is identical to a one-dimensional C++ array (i.e., the index set is a set of consecutive integers starting at 0) except for the following : 1. It performs range checking. 2.It allows one to be assigned to another array through the use of assignment operator. 3.It supports a function that returns the size of the array.