Practical 5


Aim:- Write a program to accept a line and check how many consonants and vowels are there in line.

JAVA Code :-

import java.lang.*;
import java.io.*;

class pra5
{
    public static void main(String args[])
   {
       int len,i,j,v=0,c=0,w=0;
       BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
       String str=new String();
       char vow[]={'a','e','i','o','u'};
       char ch;

       System.out.print("Enter your string: ");
       str=in.readLine();
    
        len=str.length();    

     for(i=0;i<len;i++)
     {
            ch=str.charAt(i);
            
if(Character.isWhitespace(ch))
                        w++;
            else if(Character.isDigit(ch))
                        w++;
            for(j=0;j<5;j++)
           {
                if(ch==vow[j])
                          v++;
            }
      }
    c=len-v-w;

    System.out.println("Length= "+len);
    System.out.println("Vowels= "+v);
    System.out.println("Consonants= "+c);  
  }
}

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