import java.util.ArrayList; import java.util.Scanner; public class ReverseWords { static Scanner Scan = new Scanner (System.in); public static void main(String args[]) { System.out.println("Enter a list of words, one per line. Final word should be a period (.)"); String words = Scan.nextLine(); reverseRecursively (words); } public static void reverseRecursively(String words) { int i; ArrayList<String> WordLists = new ArrayList<String>(); for ( i = 0; i < WordLists.toArray().length; i++) WordLists.add(words); if (words.equals(".")) { System.out.println(WordLists.toArray()[i]); System.out.println("Period"); } else { System.out.println("Enter New Word"); words = Scan.nextLine(); WordLists.add(words); reverseRecursively(words); } } }
Please help me. Why isn't my code working?