這是我的嘗試將控制檯輸入保存到數組列表並將其轉換爲字符串數組。Java。將控制檯輸入與循環保存到數組列表並將其轉換爲字符串數組
沒有語法錯誤,但它不應該如何工作。 對於建議和提示,我將不勝感激。
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.List;
import java.util.ArrayList;
public class LoeffelSprache
{
public LoeffelSprache()
{
}
public void translation()
{
System.out.println("Insert your Text here");
Scanner sc = new Scanner(System.in);
String s= sc.next();
List<String> list1 = new ArrayList<String>();
while (sc.hasNext()) {
sc.next();
list1.add(s);
}
String [] words = new String [list1.size()];
words=list1.toArray(words);
}
}
你的'main'方法在哪裏?你在調用'translation()'嗎? – brso05
'...但它不會如何工作。「 - 它應該如何工作?它是如何工作的?您需要包含所需行爲,特定問題或錯誤,以及在問題中重現問題所需的最短代碼。請閱讀如何創建[mcve]。 – azurefrog
我只是想將控制檯輸入保存到數組中。我使用BlueJ,所以主要方法是沒有必要的。 public void translation()是構造函數,它是空的。 –