I'm trying to read multiple line input like a copy past input, but I can't end the while
loop to stop reading. Here is my code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input =null;
while(sc.hasNext()) {
input=sc.next();
}
String [] split = input.split(" ");
for(int i = 0;i<split.length;i++) {
for(int j = split[i].length()-1;j>=0;j--) {
System.out.print(split[i].charAt(j));
}
System.out.print(" ");
}
sc.close();
}
}