Answers for "vowels 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
-1

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();
    }
    
}
Posted by: Guest on May-06-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language