Question
7.20 ReverseStrings Complete the code for the ReverseStrings such that the user can use a stack to store Strings and then output the Strings in
7.20 ReverseStrings
Complete the code for the ReverseStrings such that the user can use a stack to store Strings and then output the Strings in the opposite order from which they were entered. You can ignore the warning: [unchecked] unchecked cast.
Here is the output from a sample run:
the beginning of a story
is often different than
the end of a story
Reverse is:
the end of a story
is often different than
the beginning of a story
ReverseStrings.java
import java.util.Scanner; public class ReverseStrings{ public static void main(String[] args){ Scanner keyboard = new Scanner(System.in); StackInterface
ArrayBasedStack.java
public class ArrayBasedStack
}
public void pop() { if(top >= 0) { stack[top] = null; top--; } }
public String peek() { String topItem; if(top >= 0) { topItem = stack[top].toString(); } else { topItem = "The stack is empty"; } return topItem; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started