Aim:- Create a class which ask the user to enter a sentence,
and it should display count of each vowel type in the sentence. The program
should continue till user enters a word “quit”. Display the total count of each
vowel for all sentences.
import java.lang.*;
import java.io.*;
import java.util.*;
class pra8
{
public static void main(String args[])
{
int len,i,j;
int ca=0,ce=0,ci=0,co=0,cu=0;
char ch;
String str=new String();
String qui=new String("quit");
Scanner s=new Scanner(System.in);
do
{
System.out.print("Enter your string: ");
str=s.nextLine();
len=str.length();
for(i=0;i<len;i++)
{
ch=str.charAt(i);
if(ch=='a' || ch=='A')
ca++;
else if(ch=='e' || ch=='E')
ce++;
else if(ch=='i' || ch=='I')
ci++;
else if(ch=='o' || ch=='O')
co++;
else if(ch=='u' || ch=='U')
cu++;
}
System.out.println("A= "+ca);
System.out.println("E= "+ce);
System.out.println("I= "+ci);
System.out.println("O= "+co);
System.out.println("U= "+cu);
ca=cu=ce=ci=co=0;
}while(!str.equals(qui));
}
}
Output:-
import java.io.*;
import java.util.*;
class pra8
{
public static void main(String args[])
{
int len,i,j;
int ca=0,ce=0,ci=0,co=0,cu=0;
char ch;
String str=new String();
String qui=new String("quit");
Scanner s=new Scanner(System.in);
do
{
System.out.print("Enter your string: ");
str=s.nextLine();
len=str.length();
for(i=0;i<len;i++)
{
ch=str.charAt(i);
if(ch=='a' || ch=='A')
ca++;
else if(ch=='e' || ch=='E')
ce++;
else if(ch=='i' || ch=='I')
ci++;
else if(ch=='o' || ch=='O')
co++;
else if(ch=='u' || ch=='U')
cu++;
}
System.out.println("A= "+ca);
System.out.println("E= "+ce);
System.out.println("I= "+ci);
System.out.println("O= "+co);
System.out.println("U= "+cu);
ca=cu=ce=ci=co=0;
}while(!str.equals(qui));
}
}
Output:-
No comments:
Post a Comment