Lines should be read from the user until the sentinel "DONE" is entered, at which point they are displayed in reverse. Do not print the word "DONE"
here is my code so far i am not sure how to get it all to work together i know i have been overthinking this but any help will be appreciated
import java.util.Scanner;
import java.util.Stack;
public class Turner_A05Q3{
public static void main(String[] args) {
Stack<String> stack = new Stack<String>();
ArrayList<String> list = new ArrayList<String>();
System.out.println("Enter text, or done to stop");
Scanner scanner = new Scanner(System.in);
List<String> al = new ArrayList<String>();
String word;
while (scanner.hasNextLine()) {
word = scanner.nextLine();
if (word != null) {
word = word.trim();
if (word.equalsIgnoreCase("done")) {
break;
}
al.add(word);
} else {
break;
}
}
for (int i=0;i<word.length();i++){
stack.push(word.substring(i,i+1));
}
String wordrev = "";
while(!stack.isEmpty()){
wordrev += stack.pop();
}
System.out.println("Reverse of the text \"" + wordrev);
}
}