ストリングスの印刷について質問があります。プログラムは次のジョブを実行する必要があります: パラメータとして文字列を取得し、単語を識別して、それらを 3 列に並べて出力します: 例:
the quick brown fox jumped over the lazy dog
出力は次のようになります。
the quick brown
fox jumped over
the lazy dog
私の解決策は
private void printColumn(String s){
StringTokenizer toker = new StringTokenizer(s);
while (toker.hasMoreTokens()){
String temp = "";
for (int i = 0; i < 3; i++){
temp +=toker.nextToken();
}
System.out.print(temp);
System.out.println();
}
}
しかし、私の出力は整列していません
the quick brown
fox jumped over
the lazy dog
アドバイスをお願いします。