私がやろうとしているのは、ファイルを読み取り、を使用してStringBuilder
、ファイル内にある文字列の行の順序を逆にすることです。while ループ内で動作するようにしましたが、メソッドに追加すると、元のファイル テキストが出力されます。
これが機能するコードです。
// File being read....
while ((currentString = s.next()) != null) {
a.insert(0, currentString);
a.insert(0," ");
}
印刷する
line. this reads it hope I file. this read will program This
動作しないコードは次のとおりです。
// File being read....
while ((currentString = s.next()) != null) {
System.out.print(reverse(currentString));
}
方法
public static StringBuilder reverse(String s){
StringBuilder a = new StringBuilder();
a.insert(0, s);
a.insert(0," ");
}
印刷する
This program will read this file. I hope it reads this line.
私は何を間違っていますか?