Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Saturday, 5 November 2011

Write a program that store (a, e, i, o and u) in string data type. Then ask the user to enter a string of characters. then the program should count the number of vowels in that string (by Tieqa)


import java.util.*;
class charvowels
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
char vowels[] = new char[10];
String str;
char c1,c2;
int t=0;

vowels[0] = 'A';
vowels[1] = 'a';
vowels[2] = 'E';
vowels[3] = 'e';
vowels[4] = 'I';
vowels[5] = 'i';
vowels[6] = 'O';
vowels[7] = 'o';
vowels[8] = 'U';
vowels[9] = 'u';

System.out.print ("\n\t Enter the string = ");
str=in.nextLine();

System.out.print ("\n\n\t Vowels in the string = ");
for (int i=0;i<str.length();++i)
{
c1=str.charAt(i);
for (int j=0;j<10;++j)
{
if (c1==vowels[j])
{
System.out.print (" "+c1);
++t;
break;
}
}
}

System.out.println ("\n\t Total number of vowels = "+t);
}
}

2 comments:

  1. I haven’t cheсkеd in hеre for а while since I thought it wаs gеttіng borіng, but
    the last ѕеveral pοsts aгe greаt quality so I guess I will adԁ you bаck to my everydaу bloglist.
    Υou dеserve it fгiend :)
    Here is my site : augen op kosten

    ReplyDelete
  2. Hi, ϳust wanted to tell you, I lоvеd this aгticle.

    It was funny. Keep on роsting!
    Look at my web page : laptops special

    ReplyDelete