我无法弄清楚这段代码有什么问题。无论我提供什么作为输入,代码打印我作为输出。任何帮助表示赞赏。程序打印最多元音字数
public class VowelClass{
public static void main(String args[]){
String input;
System.out.println("Please enter your sentence: ");
Scanner scan = new Scanner(System.in);
input = scan.nextLine();
int maxVCount = 0;
String mostVowels = null;
String[] words = input.split("");
for (String word : words) {
int vCount = 0;
word = word.toLowerCase();
for (int i=0; i<word.length(); i++){
char x = word.charAt(i);
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'){
vCount++;
}
}
if (vCount > maxVCount) {
maxVCount = vCount;
mostVowels = word;
}
}
System.out.println("Word with most vowels is:");
System.out.println(mostVowels);
}
}
你可以改变你的'input.split(“”)''input.split(“”);' – Orin
谢谢!这是尴尬 – wibwaj
在未来,尝试调试或SOP门控你的输出,即'System.out.println(word);'出于理智检查的目的。最快的方式找到一个错字。 – Compass