Pages

Saturday, 8 October 2016

Question:-
Write a program to print the vowels used in the given string of input.

Input Specification :
Input will be a sentence.

Output Specification :
Your program should print the total number of vowels in the sentence (repetitions allowed) in first line and in second line print all the vowels used separated by spaces.

Sample Input :
Elephant Is a Huge Animal

Sample Output:
10
E e a I a u e A i a

Source Code:-

import java.util.*;

class Vowels{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        String str=s.nextLine();
        int count=0;
        String temp="";
        for(char c:str.toCharArray()){
            if("aAeEiIoOuU".contains(c+"")){
                count++;
                temp=temp+c+" ";
            }
        }
        System.out.println(count+"\n"+temp);
    }
}

No comments:

Post a Comment