5th sem OOPJ Write a program to accept a line and check how many consonants and vowels are there in line.

import java.io.*;

/**
 *
 * @author Yash
 */

class pra5{
    public static void main(String arg[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char ch;
        int vol=0,cont=0;
        System.out.println("Write a line :");
        String str  = br.readLine();
       
        for(int i=0;i<str.length();i++){
            ch = str.charAt(i);
            if( ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U'){
                vol++;
            }else{
                cont++;
            }
        }
        System.out.println("voweles : "+vol);
        System.out.println("Consonants :" +cont);
    }  
}

Comments

Popular posts from this blog

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

SQL Lab1: Create a Database Table for DayCare

SQL Lab 11