我需要獲取此代碼以接受用戶輸入並告訴我有多少單字母單詞,雙字母單詞,有三個字母的單詞等等。這段代碼編譯,但它只給了我使用最多字母的單詞的次數。例如,如果用戶輸入是「我想知道爲什麼這不起作用」輸出將是一個七個字母的單詞。它並不告訴我使用了多少次所有其他數量的字母單詞。這是隻返回最大的字母詞,當我想要它返回每個字母詞的計數
import java.util.*;
import java.io.*;
public class Analysis B { //open class
public static String input;
public static String stringB;
public static void main (String args []) { //open main
System.out.println("Please enter a line of text for analysis:");
Scanner sc = new Scanner(System.in);
input = sc.nextLine();
input = input.toLowerCase();
System.out.println("Analysis B:");//Analysis B
System.out.println("Word length: " + " Frequency: ");
System.out.println(AnalysisB(stringB));
} // close main
public static String AnalysisB (String stringB) { // open analysis B
String [] words = input.split(" ");
int largest = 0;
for (int i = 0; i < words.length; i++) { //open for
largest = Math.max(words[i].length(), largest); // get the largest value
} //close for
int [] frequencies = new int[ largest + 1 ];
for (int i = 0; i < words.length; i++) { //open for
frequencies[words[i].length()]++;
} //close for
for (int i = 0; i < frequencies.length; i++) { //open for
if (frequencies[i] > 0) { //open if
stringB =(i + "-letter words" + " " + frequencies[i]);
} //close if
} //close for
return stringB;
} // close analysis B
} //close class