-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvowels.java
More file actions
40 lines (40 loc) · 870 Bytes
/
Copy pathvowels.java
File metadata and controls
40 lines (40 loc) · 870 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.Scanner;
public class vowels
{
public static void main(String[] args)
{
System.out.println("Enter the string");
Scanner st = new Scanner(System.in);
String str = st.nextLine();
char[] ch = str.toCharArray();
int x=0,y=0;
for(int i=0;i<ch.length;i++)
{
if(ch[i] == 'a' || ch[i] =='e' || ch[i] =='i' || ch[i] =='o' || ch[i] =='u' || ch[i] == 'A' || ch[i] =='E' || ch[i] =='I' || ch[i] =='O' || ch[i] =='U')
{
x++;
}
}
System.out.println("Number of vowels in the string is "+x+" by using if statement");
for(char A: ch)
{
switch(A)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
y++;
break;
default:
}
}
System.out.println("Number of vowels in the string is "+y+" by using switch case");
}
}