Does anyone see, why the second and third condition do not validate? Thanks for your suggestions!
package com.codegym.task.task07.task0714;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
/*
Words in reverse
*/
public class Solution {
public static void main(String[] args) throws Exception {
// Declare a ArrayList<String> variable and immediately initialize it.
ArrayList <String> list = new ArrayList<>();
// Read 5 lines from the keyboard and add them to the list.
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 5; i++) {
String s = reader.readLine();
list.add(s);
}
// Remove the third element of list.
list.remove(2);
// Display the items on the screen, each on a new line. The display order must be reversed.
ArrayList<String> listReverse = new ArrayList<>();
for(int i = list.size() - 1; i >=0; i--) {
// get current element
String element = list.get(i);
// add it to the new list
listReverse.add(element);
}
for (int k = 0; k <= listReverse.size() -1; k++) {
System.out.println(listReverse.get(k));
}
}
}