Answer:
import java.util.*;
public class num3 {
public static void main(String[] args) {
String sentence = "All good people";
System.out.println("The vowels in the sentence are ");
returnVowels(sentence);
}
public static void returnVowels(String word){
String newWord = word.toLowerCase();
String vowels ="";
for (int i = 0; i < newWord.length(); i++){
if(newWord.charAt(i)=='a'||newWord.charAt(i)=='e'||newWord.charAt(i)==i||
newWord.charAt(i)=='o'||newWord.charAt(i)=='u'){
vowels = vowels+newWord.charAt(i);
//System.out.print(newWord.charAt(i)+" ");
}
}
String [] chars = vowels.split("");
Set<String> uniqueVowels = new LinkedHashSet<>();
for (String s : chars) {
uniqueVowels.add(s);
}
System.out.println(uniqueVowels);
}
}
Step-by-step explanation:
In Java
Create the method/function to receive a string as argument
Change the string to all small letters using the toLowerMethod
Iterate through the string using if statement identify the vowels and store in a new String
Since the sentence does not contain unique vowel characters, use the set collections in java to extract the unique vowels and print out