My code cannot reverse each line of the input. It should be look like: Input:
abc
def
ghi
Output:
cba
fed
ihg
How to modify it?
import java.*;
import java.util.Scanner;
public class Reverse {
public static void main(String[]args) {
Scanner in = new Scanner(System.in);
String s = new String();
while (in.hasNextLine()) {
s += in.nextLine() + "\n";
}
StringBuffer r = new StringBuffer(s);
r = r.reverse();
System.out.println(r);
}
}