-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCount_VowelsConstants.java
More file actions
22 lines (21 loc) · 1.02 KB
/
Count_VowelsConstants.java
File metadata and controls
22 lines (21 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// WAP to count the Vowels and Constants in a string
import java.util.Scanner;
public class Count_VowelsConstants {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the word: ");
String str = sc.nextLine();
str = str.toLowerCase(); // this will remove all the case sensitivity things like
int Vcount = 0;
int Ccount = 0;
for (int i = 0; i < str.length(); i++) {
if(str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u'){
Vcount++;
} else if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') { // This Condition will not add/count whitespaces in it so it will only count the letters and excluding the number and whitespaces
Ccount++;
}
}
System.out.println("The Number of Vowels: "+Vcount);
System.out.println("The Number opf Constants: "+Ccount);
}
}