I'm trying to read a txt file and print the line opposite. for example: txt:
3 //size of matrix
3 4 5
5 6 7
6 7 8
output should be:
6 7 8
5 6 7
3 4 5
I wrote a program. the program prints:
5 6 7
3 4 5
which is without the first line: 6 7 8
.
What is my mistake?
public static void main (String[] args) {
int matrixSize = StdIn.readInt();
String [] array = new String [matrixSize];
for (int i=0; i <= matrixSize-1; i++)
{
array[i] = StdIn.readLine();
StdOut.println(array[i]);
}
for (int j=matrixSize-1; j >= 1; j--)
{
StdOut.println(array[j]);
}
}