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
1String str = "hello";
2String vowels = "aeiou";
3
4for(char c : str) if(vowels.contains(c)) System.out.println(c + "");
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}