1// There are many ways to do it the one i came up with is this:
2int count = 0;
3String sentence = "My name is DEATHVADER, Hello World!!! XD";
4char[] vowels = {'a', 'e', 'i', 'o', 'u'};
5for (char vowel : vowels)
6 for (char letter : sentence.toLowerCase().toCharArray())
7 if (letter == vowel) count++;
8System.out.println("Number of vowels in the given sentence is " + count);
9
10// I have found another easier method if you guyz don't understand this
11// but this is also easy xD.
12// here you can see another method:
13// https://www.tutorialspoint.com/Java-program-to-count-the-number-of-vowels-in-a-given-sentence
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 + "");