我想要做的是读取一个文件并使用StringBuilder
来颠倒文件内部是一串字符串的顺序。 我知道它在while循环中工作,但是当我将它添加到一个方法时,它只是打印出原始文件的文本。Java方法撤消算法
下面是可用的代码;
// 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.
我在做什么错?