import java.util.ArrayList;
import java.util.Scanner;
public class Main {
//a normal array would be declared like this:
//String[] linesRead = new String[100];
//ArrayLists (Dynamic Arrays) are declared like this:
static ArrayList<String> linesRead = new ArrayList<String>();
//At this point, linesRead is an empty ArrayList
//this is our main function that is statically called by Java Runtime
public static void main(String[] args) {
//The scanner class can be used to parse standard input, or even files
//here we pass standard input (System.in)
Scanner s = new Scanner(System.in);
//some number to count lines with
int lines = 0;
//s.hasNext() checks if we have reached EOF
while(s.hasNext()){
//s.nextLine() returns the next line on the input stream
String line = s.nextLine();
//we add every line into the ArrayList called linesRead
linesRead.add(line);
//we increment the line count
lines++;
}
//We have some output
System.out.println("There are this many lines: " + lines);
/*
//This for loop prints things out, first to last
for(int i = 0; i < linesRead.size(); i++){
System.out.println(linesRead.get(i));
}
*/
//This for loop prints things out, last to first
for(int i = linesRead.size() - 1; i >= 0; i--){
//Members in normal arrays are accessed with brackets: somelist[index]
//ArrayList members are accessed with the get() method
System.out.println(linesRead.get(i));
}
//Our Scanner object should be closed before the program ends
s.close();
}
}