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 try to lead me in the right direction. i have been at this for a while and I am really frustrated. It was to do something with my logic I just don't know what.
This post has been edited by jon.kiparsky: 26 September 2013 - 07:39 AM
Reason for edit:: removed gratuitous whitespace

New Topic/Question
Reply


MultiQuote



|