下面是一个示例的Java程序,其中包含一个名为getVowel()的函数,该函数接受一个链表作为参数,用于获取链表中的元音字母:
import java.util.LinkedList;
public class VowelExample {
public static void main(String[] args) {
LinkedList list = new LinkedList<>();
list.add('a');
list.add('b');
list.add('c');
list.add('d');
list.add('e');
LinkedList vowels = getVowel(list);
System.out.println("Vowels in the list are: " + vowels);
}
public static LinkedList getVowel(LinkedList list) {
LinkedList vowels = new LinkedList<>();
for (Character ch : list) {
if (isVowel(ch)) {
vowels.add(ch);
}
}
return vowels;
}
public static boolean isVowel(char ch) {
ch = Character.toLowerCase(ch);
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}
}
在上面的代码中,我们创建了一个名为VowelExample的类,其中包含了一个getVowel()函数和一个isVowel()函数。getVowel()函数接受一个LinkedList
在main()函数中,我们创建了一个包含一些字母的链表,并调用getVowel()函数来获取其中的元音字母。最后,我们打印出获取到的元音字母链表。
输出结果为:
Vowels in the list are: [a, e]
上述程序中,我们假设元音字母为a、e、i、o、u。如果你需要其他的元音字母,请根据需要修改isVowel()函数。