public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] words = new String[5];
for(int i=0;i<5;i++){
words[i] = reader.readLine();
}
ArrayList<String> list1 = new ArrayList<String>();
for(int i=0;i<5;i++){
list1.add(words[i]);
}
list1.remove(2);
ArrayList<String> listReverse = new ArrayList<String>();
for(int i=0;i<4;i++){
listReverse.add(list1.get(4-i));
}
printList(listReverse);
}
public static void printList(ArrayList<String> list){
for(String x: list)
System.out.println(x);
}
}
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 {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] words = new String[5];
for(int i=0;i<5;i++){
words[i] = reader.readLine();
}
ArrayList<String> list1 = new ArrayList<String>();
for(int i=0;i<5;i++){
list1.add(words[i]);
}
list1.remove(2);
ArrayList<String> listReverse = new ArrayList<String>();
for(int i=0;i<4;i++){
listReverse.add(list1.get(4-i));
}
printList(listReverse);
}
public static void printList(ArrayList<String> list){
for(String x: list)
System.out.println(x);
}
}