import java.io.*;
import java.util.*;
public class Reverseing
{
public static void main(String[] args) throws Exception
{
File f = new File("backwards.txt");
Scanner finput = new Scanner(f);
String sentence = "", s = "", r = "";
while(finput.hasNext())
{
sentence = s + finput.nextLine();
}
ArrayList<String> lines = new ArrayList<String>();
ArrayList<String> words = new ArrayList<String>();
while (input.hasNextLine()) {
line = input.nextLine();
}
for (int i = 0; i < list.size(); i++) {
String s = list.get(i);
sum += s.length();
}
String[] toks = sentence.split(" ");
for(int i = toks.length - 1 ; i >= 0; i--) {
r = r + toks[i] + " ";
}
System.out.println(r);
}
}
program to reverse the lines of a file and also to reverse the order of the words in each line of the file. Use an ArrayList for the lines of the file and for the words of each line. Print out the lines to demonstrate that the lines and each word of each line have been reversed.
Example- "This is a test." should be reversed to read: "test. a is This"