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

Java program to create an ARRAY of 5 STRINGS. The program finds and displays the total number of vowels (both uppercase and lowercase) in all five strings by (Adler Lawn Service, LLC)


import java.util.*;
class vowels
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
String n="",n1,n2,n3,n4,n5;
char c;
int r=1;

System.out.print ("\n\t Enter first name of first person = ");
n1 = in.nextLine();
System.out.print ("\n\t Enter first name of second person = ");
n2 = in.nextLine();
System.out.print ("\n\t Enter first name of third person = ");
n3 = in.nextLine();
System.out.print ("\n\t Enter first name of fourth person = ");
n4 = in.nextLine();
System.out.print ("\n\t Enter first name of fifth person = ");
n5 = in.nextLine();

while (r<6)
{
if (r==1)
{
n=n1;
System.out.print ("\n\n\t Vowels in first person's name = ");
}
else if (r==2)
{
n=n2;
System.out.print ("\n\n\t Vowels in second person's name = ");
}
else if (r==3)
{
n=n3;
System.out.print ("\n\n\t Vowels in third person's name = ");
}
else if (r==4)
{
n=n4;
System.out.print ("\n\n\t Vowels in fourth person's name = ");
}
else if (r==5)
{
n=n5;
System.out.print ("\n\n\t Vowels in fifth person's name = ");
}
else
System.out.println ();

for (int i=0;i<n.length();++i)
{
c=n.charAt(i);
switch (c)
{
case 'A':
case 'a':
System.out.print (" "+c);
break;
case 'E':
case 'e':
System.out.print (" "+c);
break;
case 'I':
case 'i':
System.out.print (" "+c);
break;
case 'O':
case 'o':
System.out.print (" "+c);
break;
case 'U':
case 'u':
System.out.print (" "+c);
break;
default:
System.out.print ("");
}
}

++r;
}

}
}

No comments:

Post a Comment