我有一個程序,我有一個輸入的句子。該句子使用regEx/split方法分解成單詞。單詞存儲在名爲wordsInLine的數組中,我的工作是將這些單詞添加到名爲WordList的ArrayList中。使用哈希/列表輸出每個單詞句子
如果我們找到WordList和wordsInLine之間的匹配,我們繼續閱讀下一個單詞等等,等等。我的工作是輸出每個單詞。
預期輸入=遊戲的得分是五到五。
預期輸出:
一句話:
字:分數
字:中
一句話:
於是就等
主類:
個package proj1;
import java.util.ArrayList;
public class Proj1 {
public static void main(String[] args) {
int lineWord = 0, listWord = 0;
String inputLine = "The score of the game is five to five";
String regEx = "(, *)|(: *)|\\s";
String[] wordsInLine;
ArrayList<Word> wordList = new ArrayList<Word>();
wordsInLine = inputLine.split(regEx);
if (wordList.isEmpty())
System.out.println("Empty List");
}
}
詞類:
package proj1;
class Word {
String Word;
int timesWordIsRepeated;
public Word (String words, int count) {
words = Word;
}
public String getWord() {
return Word;
}
@Override
public String toString() {
String theString = String.format("Word :",Word);
return theString;
}
}
這將是有用的,如果你能確切地解釋(並舉例說明)您對特定輸入的期望輸出。 (您已經解釋了您計劃解決問題的方法,但您試圖解決的問題是什麼?也許有更好的方法來解決問題。) –
對不起。我在尋找的輸出僅僅是這樣的: 一句話: 字:分數 字:中 一句話: 字:遊戲 字:是 字:五 字:要 字:五 – Mike
我我很困惑這意味着什麼。我正在尋找的是具體的例子:投入和預期產出。你可以修改原來的問題來添加這些例子。 –