-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindVowels.java
More file actions
27 lines (27 loc) · 874 Bytes
/
findVowels.java
File metadata and controls
27 lines (27 loc) · 874 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
//Question: Find number of vowels in a string.
package strings;
import java.util.Scanner;
public class findVowels {
public static void main(String[] args) {
String s;
System.out.print("Enter the string: ");
Scanner sc=new Scanner(System.in);
s=sc.nextLine();
int count=0;
for(int i=0; i < s.length(); i++){
char ch = s.charAt(i);
if (isVowel(ch)==true) {
count++;
}
}
System.out.println("Number of vowels are: " + count);
}
public static boolean isVowel(char ch){
if(ch=='a' || ch=='A') return true;
if(ch=='e' || ch=='E') return true;
if(ch=='i' || ch=='I') return true;
if(ch=='o' || ch=='O') return true;
if(ch=='u' || ch=='U') return true;
else return false;
}
}