I have been given a text file which reads:
aaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbb
ccccccccccccccccccc
ddddddddddddddddddd
and I have to make the program display it in the this order:
ddddddddddddddddddd
ccccccccccccccccccc
bbbbbbbbbbbbbbbbbbb
aaaaaaaaaaaaaaaaaaa
So far this is my code:
public class LineReverserMain {
public static void main(String[] args) throws FileNotFoundException
{
int lineCount = 0;
ArrayList <String> LinesArray = new ArrayList<String>( );
Scanner in = new Scanner(System.in);
System.out.print("Please enter the file name: ");
String filename = in.next();
File file = new File(filename);
Scanner inFile = new Scanner(file);
while (inFile.hasNextLine()){
lineCount += 1;
String CurrentLine = inFile.nextLine();
LinesArray.add(CurrentLine);
}
System.out.println(LinesArray);
System.out.println(lineCount + " lines");
for(int linesCount = lineCount; linesCount>=0; linesCount = linesCount - 1){
System.out.println(LinesArray.get(linesCount));
}
}
}
But this doesn't seem to work.