これは非常に単純なはずですが (私はそう思います)、正しく理解できません...:|
タスクは次のとおりです。
ユーザーに入力を求めます。入力は 1 つの単語に分割し、配列に入れる必要があります。すべての単語をカウントする必要があります。等しい単語が存在する場合、それらは出力で「+1」を取得します。最後に、リスト内のカウントされた単語の適切な量を出力したいと思います。最初の 2 つの列は正しくできましたが、同じ単語の単語カウンターが頭を悩ませました。単語が等しいことがわかった場合、生成されたリストに 2 回表示されてはなりません。:!
私は完全な Java 初心者なので、コードの判断にはご注意ください。;)
これまでの私のコードは次のとおりです。
package MyProjects;
import javax.swing.JOptionPane;
public class MyWordCount {
public static void main(String[] args) {
//User input dialog
String inPut = JOptionPane.showInputDialog("Write som text here");
//Puts it into an array, and split it with " ".
String[] wordList = inPut.split(" ");
//Print to screen
System.out.println("Place:\tWord:\tCount: ");
//Check & init wordCount
int wordCount = 0;
for (int i = 0; i < wordList.length; i++) {
for (int j = 0; j < wordList.length; j++){
//some code here to compare
//something.compareTo(wordList) ?
}
System.out.println(i + "\t" + wordList[i]+ "\t" + wordCount[?] );
}
}
}