Java Blog

 
 
 
 public class JAVA_049
 {


    public static void main(String[] args)
    {
       String Text=\"To be or not to be, that is the question; Whether \'this\"
                  +\"nobler in the mind to suffer the sling and arrows of \"
                  +\"outrageous fortune, or to take arms against a sea of \"
                  +\"troubles, and by opposing end them?\";

       System.out.println(\"Text paragraph is : \" + Text + \"\\n\\n\");

       int spaces=0;
       int vowels=0;
       int letters=0;

       int text_length=Text.length( );

       char Ch;

       for(int i=0;i<text_length;i++)
       {
          Ch=Text.charAt(i);
          Ch=Character.toLowerCase(Ch);

          if(Ch==\'a\' || Ch==\'e\' || Ch==\'i\' || Ch==\'o\' || Ch==\'u\')
             vowels++;

          else if(Character.isLetter(Ch))
             letters++;

          else if(Character.isWhitespace(Ch))
             spaces++;
       }

       System.out.println(\"The Text contained vowels : \" + vowels + \"\\n\"
                         +\"                   spaces : \" + spaces + \"\\n\"
                         +\"                  letters : \" + letters );
    }
 }

 
 
Didn't find what you were looking for? Find more on Program to show an example of getting at characters in a String