java program to print vowels in a string
String str = "hello";
String vowels = "aeiou";
for(char c : str) if(vowels.contains(c)) System.out.println(c + "");
java program to print vowels in a string
String str = "hello";
String vowels = "aeiou";
for(char c : str) if(vowels.contains(c)) System.out.println(c + "");
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();
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us