Welcome to Dream.In.Code
Become a Java Expert!

Join 150,376 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,528 people online right now. Registration is fast and FREE... Join Now!




Count the vowels

 
Reply to this topicStart new topic

Count the vowels

rprabhuit
28 Jan, 2008 - 09:33 AM
Post #1

New D.I.C Head
*

Joined: 28 Jan, 2008
Posts: 1

CODE
import java.io.*;
class CharCount
{
public static void main(String args[])
  {
   String txt;
   int vowels=0;
   int letter=0;
   int spaces=0;
   txt  = new String("A VARIABLE is an identifier that used to store a value. ");
   System.out.println("\nThe Strting is    :"+txt);
   int n=txt.length();
   for(int i=0;i<n;i++)
    {
      if(txt.charAt(i)=='a'||txt.charAt(i)=='A')
      {
       ++vowels;
      }
      else if(txt.charAt(i)=='e'||txt.charAt(i)=='E')
      {
       ++vowels;
      }
      else if(txt.charAt(i)=='i'||txt.charAt(i)=='I')
      {
      ++vowels;
      }
      else if(txt.charAt(i)=='o'||txt.charAt(i)=='O')
      {
      ++vowels;
      }
      else if(txt.charAt(i)=='u'||txt.charAt(i)=='U')
      {
      ++vowels;
      }
      else if(txt.charAt(i)==' ')
      {
      ++spaces;
      }
      else
      {
      ++letter;
      }
    }
    System.out.println("\nThe Vowels are    :"+vowels);
    System.out.println("\nThe Spaces are    :"+spaces);
    System.out.println("\nThe Letters are    :"+letter);
}
}
edit: code tags added PB

This post has been edited by PennyBoki: 28 Jan, 2008 - 10:24 AM
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Count The Vowels
28 Jan, 2008 - 10:16 AM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Hi rprabhuit, please post in the proper forum and code.gif

Maybe you want to post this as a snippet? Please do tell why did you post this code.

Thanks.

This post has been edited by PennyBoki: 28 Jan, 2008 - 10:26 AM
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Count The Vowels
28 Jan, 2008 - 10:25 AM
Post #3

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
Moved to Java.

Did you have a question about this code, or were you just posting it for our edification?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:14PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month