Answers for "How to Print vowel from string in java"

0

print vowels in string java

 
package org.arpit.java2blog;
 
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
 
public class VowelFinder
{
    public static void main(String args[])
    {
        Scanner scanner = new Scanner(System.in);
 
        System.out.print("Enter an String : ");
        String str = scanner.next();
 
        Set<Character> set=new HashSet<Character>();
        for (int i = 0; i < str.length(); i++) {
            char c=str.charAt(i);
            if(isVowel(c))
            {
                set.add(c);
            }
        }
 
        System.out.println("Vowels are:");
        for (Character c:set) {
            System.out.print(" "+c);
        }
 
        scanner.close();
    }
 
    public static boolean isVowel(char character)
    {
 
        if(character=='a' || character=='A' || character=='e' || character=='E' ||
                character=='i' || character=='I' || character=='o' || character=='O' ||
                character=='u' || character=='U'){
            return true;
        }else{
            return false;
        }
    }
 
}
 
Posted by: Guest on August-02-2021
-1

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 + "");
Posted by: Guest on April-13-2021

Code answers related to "How to Print vowel from string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language