-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathConsecutive2vowels.java
36 lines (33 loc) · 1.09 KB
/
Consecutive2vowels.java
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
/*Count the number of words in a sentence that contain at least two consecutive vowels (a, e, i, o, u) in them.
Here's a sample input and output:
Input: I enjoy eating spaghetti and meatballs for dinner
Output: 2
Explanation: There are two words in the sentence that contain at least two consecutive vowels - "enjoy" and "meatballs".
*/
import java.util.*;
public class Consecutive2vowels {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine().toLowerCase();
String[] str = s.split(" ");
int count=0;
for (int i = 0; i < str.length; i++) {
for (int j = 1; j < str[i].length(); j++) {
if(isVowel(str[i].charAt(j-1))==true && isVowel(str[i].charAt(j))==true)
{
count++;
break;
}
}
}
System.out.println(count);
}
public static boolean isVowel(char c)
{
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
{
return true;
}
return false;
}
}