hello everyone could teach me how to make the user input instead of me
here my code i just needed my teststack to let the user input instead of me could tell me what to do ?
here my code i just needed my teststack to let the user input instead of me could tell me what to do ?
Code:
class Stack {
private int maxSize;
private char[] stackArray;
private int top;
public Stack(int s) {
maxSize = s;
stackArray = new char[maxSize];
top = -1;
}
public void push(char j) {
stackArray[++top] = j;
}
public char pop() {
return stackArray[top--];
}
public char peek() {
return stackArray[top];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxSize - 1);
}
}
Code:
import java.util.Scanner;
public class TestStack {
public static void main(String[] args) {
String STS = " STS";
int stackSize = STS.length();
Stack theStack = new Stack(stackSize);
for (int j = 0; j < STI.length(); j++) {
char ch = STS.charAt(j);
theStack.push(ch);
}
while (!theStack.isEmpty()) {
char ch = theStack.pop();
System.out.println(ch);
}
}
}
Comment