Say my input is
now is the time for
all good men to come to the aid of the party
The output would be:
for time the is now
party the of aid the to come to men good all
I figured out how to reverse each the whole text file but I need to do it sentence by sentence. Currently my code is outputting this:
party the of aid the to come to men good all for time the is now
Code is:
List<String> words = new ArrayList<String>();
while(sc.hasNextLine())
{
String line = sc.nextLine();
StringTokenizer st = new StringTokenizer(line);
while(st.hasMoreTokens())
{
words.add(st.nextToken());
}
}
for (int i = 0; i <words.size(); i++)
{
System.out.print(words.get(words.size()-i-1) + " ");
}