Practical 8


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.

JAVA Code :-

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:-



No comments:

Post a Comment

Programs

Home Aim:- Write a program to convert rupees to dollar. (60rupees=1 dollar). Aim:- Write a program that calculate percentage marks...