Code for Program to show an example of getting at characters in a String in Java
publicclass JAVA_049
{
publicstaticvoid 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++;
elseif(Character.isLetter(Ch))
letters++;
elseif(Character.isWhitespace(Ch))
spaces++;
}
System.out.println("The Text contained vowels : " + vowels + "\n"
+" spaces : " + spaces + "\n"
+" letters : " + letters );
}
}