-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountVowelsInString.java
More file actions
54 lines (45 loc) · 1.41 KB
/
Copy pathCountVowelsInString.java
File metadata and controls
54 lines (45 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package interviewprograms.src;
import java.util.Scanner;
/**
*
* @author al adnan sami
*/
public class CountVowelsInString {
public static void main(String[] args) {
int count=0, count1=0;
System.out.println("Enter string: ");
Scanner sc= new Scanner(System.in);
String str= sc.nextLine(); //Takes the string into str
char[] chars= str.toCharArray(); //makes string to character array
for(char c: chars){
if(c=='a'|| c=='e'||c=='i'|| c=='o'||c=='u'){
count++;
}
}
System.out.println("Number of vowels in String = "+ count);
//Another way
System.out.println("Enter Second String: ");
String str1= sc.nextLine(); //Takes the string into str
char[] chars1= str1.toCharArray(); //makes string to character array
for(char c1: chars1){
switch(c1){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
count1++;
break;
}
}
System.out.println("Number of vowels in String2 = "+ count1);
}
}
/*
Enter string:
qwertyuiop
Number of vowels in String = 4
Enter Second String:
zxcvbnm
Number of vowels in String2 = 0
*/