java program to print vowels in a string

Solutions on MaxInterview for java program to print vowels in a string by the best coders in the world

showing results for - "java program to print vowels in a string"
Maritza
30 Apr 2017
1 
2package org.arpit.java2blog;
3 
4import java.util.HashSet;
5import java.util.Scanner;
6import java.util.Set;
7 
8public class VowelFinder
9{
10    public static void main(String args[])
11    {
12        Scanner scanner = new Scanner(System.in);
13 
14        System.out.print("Enter an String : ");
15        String str = scanner.next();
16 
17        Set<Character> set=new HashSet<Character>();
18        for (int i = 0; i < str.length(); i++) {
19            char c=str.charAt(i);
20            if(isVowel(c))
21            {
22                set.add(c);
23            }
24        }
25 
26        System.out.println("Vowels are:");
27        for (Character c:set) {
28            System.out.print(" "+c);
29        }
30 
31        scanner.close();
32    }
33 
34    public static boolean isVowel(char character)
35    {
36 
37        if(character=='a' || character=='A' || character=='e' || character=='E' ||
38                character=='i' || character=='I' || character=='o' || character=='O' ||
39                character=='u' || character=='U'){
40            return true;
41        }else{
42            return false;
43        }
44    }
45 
46}
47 
48
Idris
18 Jun 2020
1String str = "hello";
2String vowels = "aeiou";
3
4for(char c : str) if(vowels.contains(c)) System.out.println(c + "");
Lea
01 Jan 2018
1import java.util.Scanner;
2import java.util.*;
3
4class Test{
5    
6    public static boolean isVowel(char ch){
7        if(ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U'){
8            return true;
9        }
10        return false;
11    }
12    
13    public static void main(String args[]){
14        
15        Scanner scan = new Scanner(System.in);
16        List<String> arr = new ArrayList<String>();
17        String str = scan.nextLine();
18        String words[] = str.split("\\s");
19        
20        for(String k: words){
21            boolean flag = false;
22            boolean f1 = true;
23            boolean f2 = true;
24            if(k.length()<=2){
25                continue;
26            }
27            for(int i = 0 ; i < k.length() ; i = i + 2){
28                if(isVowel(k.charAt(i))==false){
29                    f1 = false;
30                    break;
31                }
32            }
33            for(int i = 1 ; i < k.length() ; i = i + 2){
34                if(isVowel(k.charAt(i))==false){
35                    f2 = false;
36                    break;
37                }
38            }
39            if(f1 == true || f2 == true){
40                flag = true;
41            }
42            if(flag == true){
43                arr.add(k);
44            }
45        }
46        if(arr.size()==0){
47            System.out.print(-1);
48        }
49        else{
50            for(int i = 0 ; i < arr.size() ; i++)
51            {
52                System.out.print(arr.get(i) + " ");
53            }
54        }
55        scan.close();
56    }
57    
58}
queries leading to this page
check vowels in a string javafind vowels in string javavowels in letter javafinding vowels in a string in javahow to find the vowels in a string in javavowels check in string in javavowels in a string javaprint vowels in string javahow to count vowels in string in javastring vowels program in javajava find vowels in stringfind vowels in string using stream javafind vowels and consonants in a string in java and return function 2b javacheck is vowels in javajava program to check vowels in a stringhow to find vowels in a string javajava check for vowelsjava print vowels characters vowel program in java java write a function that takes in a string and then prints out all the vowels in the stringjava write a function that takes in a string and then prints out all the vowels in the stringvowels program in javavowels in java stringno of vowels in a string in javaprint only vowels from a string javajava print vowels characters do whilevowels code in javahow to check vowels in a string in javacheck vowels in string javafind vowels and consonants in a string in javajava program to count vowels in a string inoutprogram to print the vowels in a given sentance of length 3c 3d200 in javaopposite vowels java programprint consonants that are adjacent to vowels in string in javacalculate vowels in a string javacheck vowels in string in javaprogram to print vowels in a string in javajava program to count vowels in the stringjava program to print only vowels in a stringvowels in string in javawrite a program to calculate number of vowels present in a string and print them javafind vowels javajava program to find vowels and consonantswrite a java program to find the number of vowels in a stringwrite a java program to find the number of letters 2c vowels and consonants in a given string by using method vowels in javahow to check if there are all vowels in a string in javajava program to print vowels in a stringvowels pattern javareturn vowels java write a program on finding number of vowels in a string in javajava string and then prints out all the vowelshow to pick out vowels in a string in javapick vowels from a string in javacheck for vowels in a string javavowels javajava program to print vowels in a string