有问题可以留言提问!
import java.util.Arrays;
import java.util.Scanner;
public class Abbreviation {
public static void main(String[] args) {
int n;
Scanner in = new Scanner(System.in);
n = in.nextInt();
String arr[]=new String[n];
char [] danci;
for(int i=0;i<n;i++) //输入n个单词
{
arr[i]=in.next();
}
for(int i=0;i<n;i++) //将每个单词转换为字符数组,调用函数删除字母
{
danci=arr[i].toCharArray();
danci=deleteChar(danci, 'a');
danci=deleteChar(danci, 'e');
danci=deleteChar(danci, 'i');
danci=deleteChar(danci, 'o');
danci=deleteChar(danci, 'u');
System.out.println(danci);
}
in.close();
}
public static char[] deleteChar(char danci[], char aim) {
for (int i = 0; i < danci.length;) {
if (danci[i] == aim) {
for (int j = i + 1; j < danci.length; j++) {
danci[j - 1] = danci[j];
}
danci = Arrays.copyOf(danci, danci.length - 1);
} else {
i++;
}
}
return danci;
}
}