-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp5.java
More file actions
24 lines (22 loc) · 764 Bytes
/
p5.java
File metadata and controls
24 lines (22 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Write a program to accept a line and check how many consonants and vowels are there in line.
*/
import java.util.Scanner;
public class p5 {
public static void main(String args[]) {
Scanner s1 = new Scanner(System.in);
System.out.println("Enter string : ");
String str = s1.nextLine();
int vowel = 0;
String tmp_str = str.toLowerCase();
for(int i = 0; i < str.length(); i++) {
switch(tmp_str.charAt(i)) {
case 'a' : case 'e' : case 'i' : case 'o' : case 'u' :
vowel++;
break;
}
}
System.out.println(str + " : ");
System.out.println("Vowels : " + vowel + "\nConsonents : " + (str.length() - vowel) );
}
}