这是程序谁能帮助我 起初我给字符串第一部分工作正常发现的元音字符串,并将其打印删除重复的元音字母在一个字符串
public static void main(String[] args) {
// TODO Auto-generated method stub
String a = "History can also refer to the academic discipline ";
int count = 0;
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) == 'a' || a.charAt(i) == 'e' || a.charAt(i) == 'i' || a.charAt(i) == 'u'
|| a.charAt(i) == 'u') {
System.out.println("The sentence have vowels:" + a.charAt(i));
count++;//counting the number of vowels
}
if (a.charAt(i+1) == 'a' || a.charAt(i+1) == 'e' || a.charAt(i+1) == 'i' || a.charAt(i+1) == 'u'
|| a.charAt(i+1) == 'u') {i++;}//finding reoccurring vowels
}
System.out.println("number of vowels:" + count);
}
}
在第二部分我尝试跳过重现的元音,但它不工作
*** a.charAt第(i + 1)***,这将爆炸n的for循环 –
最后一次迭代你正在检查'你'2次和'0'零次 –
我的坏我输入“u”而不是“o”,但仍然我无法消除反复出现的元音,所以我应该怎么做才能纠正它 –