2016-07-05 1 views
0

このコードで何が問題なのかわかりません。私が入力として提供するものであれば、コードはiを出力として出力します。どんな助けもありがとうございます。ほとんどの母音を含む単語を印刷するプログラム

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); 
    } 
} 
+0

'input.split(" ")'を 'input.split(" ");に変更できますか? – Orin

+0

ありがとう!あたかも恥ずかしがり屋であった – wibwaj

+0

将来的には、健全性チェックの目的で、出力、つまり 'System.out.println(word);のデバッグやSOPゲーティングを試みてください。タイプミスを見つける最速の方法。 – Compass

答えて

1

input.split(""); =>input.split(" ");

あなたは言葉の間で分割するので、分割方法に '空白' 文字を使用する必要があります。

+0

恥ずかしい!おかげさまでアレックス。 – wibwaj

+0

フライバイ、クワイ、黄色、または強さの中で最も母音のある単語はどれですか? – FredK

+0

確かに。イエローは勝者です:) – wibwaj

関連する問題