Java program to calculate occurrence of consonants and vowels in given line
Simple Java program to calculate the number of consonants and vowels present in given line
Code:
import java.util.Scanner;class p82{public static void main(String args[]){
String s = new String();
int co=0,cs=0;
Scanner sc = new Scanner(System.in);
s=sc.nextLine();
for(int i=0;i<s.length();i++){
char c = s.charAt(i);
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U'){co++;}
else if(!(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U') && ((c>=65 && c<=90) || (c>=97 && c<=122))){cs++;}
}
System.out.println("Vowels: "+co);
System.out.println("Consonant: "+cs);
}}
Comments
Post a Comment