-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathVowelsInAString.java
More file actions
25 lines (22 loc) · 884 Bytes
/
VowelsInAString.java
File metadata and controls
25 lines (22 loc) · 884 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
/* @date 13/10/2020
* @author Shashwat Gupta (shashwatxdevelop)
*/
import java.util.Scanner;
public class VowelsInAString {
public static void main(String[] args) {
String s; int k = 0, l, i; char ch = 0;
Scanner sc = new Scanner (System.in);
System.out.println("Enter the string");
s = sc.nextLine(); //taking input as string
l = s.length(); //finding length of the string
for (i=0; i<l; i++)
{
ch= s.charAt(i); //extracting the character from the string
if(ch=='a' || ch == 'A' || ch == 'e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch== 'O'|| ch=='u' || ch=='U')
{
k++; //increasing the counter variable by 1 if vowel is found
}
}
System.out.println("Number of vowels in the string is " + k); //printing the total number of vowels in the string
}
}