I set all elements to ""
then read in 8 strings ok
when it prints out it shows all ten elements in reverse order - starting with element [9] and element [8] as ""
it wont validate . any suggestions please.
many thanks
package com.codegym.task.task07.task0702;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
String array in reverse order
*/
public class Solution {
public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static String [] tenStrings=new String[10];
public static void main(String[] args) throws Exception {
//initialise the array set all string elements to ""
for(int k=0;k<10;k++){
tenStrings[k]="";
}
//read in 8 strings
for (int i=0;i<8;i++){
tenStrings[i] = reader.readLine();
}
//display 10 array elements in reverse order
for (int j=10;j>0;j--){
System.out.println(tenStrings[j-1]);
}
}
}