Question: Please include a main to see the output. Question 3 : Write a method in the Demo class ( name it reverseString ) , call
Please include a main to see the output.
Question :
Write a method in the Demo class name it reverseString call the method from the main and pass a string to it This method will do the following:
Receives a string sentence not just one word
Stores the received string in an linkedlistbased stack
Prints the sentence in reverse.
Example:
Call statement: reverseStringTesting my reverseString method";
output: dohtem gnirtSesrever ym gnitseT
Question :
Write a method in the Demo class name it reverseNumber call the method from the main and pass an integer to it This method will do the following:
Receives an integer.
Stores the received integer in an arraybased stack
Prints the integer in reverse.
Example:
Call statement: reverseNumber;
output:
Demo class below
public class LinkedStack
private Node top null;
public boolean empty
return top null;
public void pushString s
top new Nodes top;
public String pop
String retValue;
if empty
throw new IllegalStateException;
else
retValue top.element;
top top.next;
return retValue;
public String peek
if empty
throw new IllegalStateException;
else
return top.element;
public String toString
Node ref top;
String toPrint ;
while ref null
toPrint ref.element;
ref ref.next;
return toPrint;
Node class used for linked list
private class Node
String element;
Node next;
NodeString e Node n
element e;
next n;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
