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);
}
}
/**
*
* @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
Post a Comment