【发布时间】:2014-05-11 05:48:58
【问题描述】:
我用了reverse一个字符串,但现在需要的是最终文件的原理,反之亦然:
Hello
Bye
到
Bye
hello
而不是:
olleH
eyB
当我这样做的时候?
这是我的来源:
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Sintaxis incorrecta, introduzca el nombre del fichero");
System.exit(1);
}
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(args[0]));
String s;
try {
while ((s = br.readLine()) != null) {
StringBuilder reverse = new StringBuilder(s);
String sCadenaInvertida = reverse.reverse().toString();
System.out.println(sCadenaInvertida);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
谢谢!!
【问题讨论】:
-
请改写
but now need the final document is the principle, and vice versa:。这没有意义。 -
分词,逆向集合,使用空格加入
-
你需要获取String,使用
split获取单词数组,然后新建一个String,按降序读取单词。简单:D -
在发布问题之前,请先查看预览部分,看看您的问题是否正确显示了您的问题。我稍微编辑了您的问题以显示您如何编写示例,但我不确定为什么有些大写变成小写,所以添加更多有关输入和预期输出的信息。
-
现在看来您需要类似 FILO 的结构(如堆栈),或者只需将每一行添加到某个列表中,然后在完成添加 read it backward 之后。
标签: java string bufferedreader reverse stringbuilder