Project 11 ArrayLists Write a program to reverse the lines o
Project 11 ArrayLists Write a program to reverse the lines of a file and also to reverse the order of the words in each line of the file. Use ArrayLists to help you
****Java programming****
Solution
This is the program for given question and please do let me know if any errors occur
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);
}
}

