how to check if there are all vowels in a string in java code example
Example: string vowels program in java
import java.util.Scanner;
import java.util.*;
class Test{
public static boolean isVowel(char ch){
if(ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U'){
return true;
}
return false;
}
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
List<String> arr = new ArrayList<String>();
String str = scan.nextLine();
String words[] = str.split("\\s");
for(String k: words){
boolean flag = false;
boolean f1 = true;
boolean f2 = true;
if(k.length()<=2){
continue;
}
for(int i = 0 ; i < k.length() ; i = i + 2){
if(isVowel(k.charAt(i))==false){
f1 = false;
break;
}
}
for(int i = 1 ; i < k.length() ; i = i + 2){
if(isVowel(k.charAt(i))==false){
f2 = false;
break;
}
}
if(f1 == true || f2 == true){
flag = true;
}
if(flag == true){
arr.add(k);
}
}
if(arr.size()==0){
System.out.print(-1);
}
else{
for(int i = 0 ; i < arr.size() ; i++)
{
System.out.print(arr.get(i) + " ");
}
}
scan.close();
}
}