Stack Adding Machine wird nicht hinzugefügt, wartet jedoch auf weitere Argumente

Ich habe also einen Stapel, den ich erstellt habe, und ich habe eine Maschine, um Ausdrücke wie (9 + 0) auszuwerten, und sie können komplexer sein. Ich führe es spaßig über die Kommandozeile aus und wenn ich dann das Beispiel (9 + 5) eingebe, sitzt das Programm einfach da. Ich kann eine neue Zeile erhalten, aber der Ausdruck wird nicht ausgewertet. Meine Frage ist also, was ich vermisst habe. Ich bin sicher, dass es etwas gibt, das ich nicht richtig verstanden habe und ich dachte, dass mir etwas über den Scanner oder über Arrays in Java im Allgemeinen fehlt.

Vielleicht habe ich letzte Nacht darüber nachgedacht, Arrays durch ArrayList zu ersetzen. Macht das Sinn?

Hier ist der Stapel mit fester Kapazität

public class FCStack<Item> {

private Item[] a; 
private int top; // pointer to top of Stack
private int capacity; // size of the Stack+1

public FCStack(int cap){
    capacity = cap;
    a = (Item[]) new Object[capacity];   
    top = 0;
}

public void push(Item i){ //will only push an Item to the Stack if there is room. 
    if (!isFull()) {
        a[top++] = i;
    }
}

public Item pop(){ //will only pop an Item from the stack if there is something to pop.
    if (!isEmpty()) {
        --top;
    }
    return a[top];
}

public boolean isFull(){ //returns true if is full
    return top == capacity;
}

public boolean isEmpty(){ //returns true if is empty
    return top == 0; 
}

public int size(){ //returns the current size of the stack+1 or the array index 
    return top;
}

}

Hier ist der Two Stack Evaluator

import java.io.*;
import java.util.Scanner;

public class TwoStackMaths {

public static void main (String[] args) {
    FCStack<String> ops = new FCStack<String>(10);
    FCStack<Double> vals = new FCStack<Double>(10);
    Scanner console = new Scanner(System.in);
    while(console.hasNext()) {
        String str = console.next();
        if (str.equals("("))
            ;
        else if (str.equals("+")) {
            ops.push(str);
        }
        else if (str.equals("-")) {
            ops.push(str);
        }
        else if (str.equals("*")) {
            ops.push(str); 
        }
        else if (str.equals("/")) {
            ops.push(str);
        }
        else if (str.equals("^")) {
            ops.push(str);
        }
        else if (str.equals(")")) {
            String op = ops.pop();
            double v = vals.pop();
            if (op.equals("+")) {
                v = vals.pop() + v;
            }
            else if (op.equals("-")) {
                v = vals.pop() - v;
            }
            else if (op.equals("*")) {
                v = vals.pop() * v;
            }
            else if (op.equals("/")) {
                v = vals.pop() / v;
            }
            else if (op.equals("^")) {
                v = Math.pow(v, vals.pop());
            }
            vals.push(v);
        }
        else {
        vals.push(Double.parseDouble(str));
        }
    }
    //console.close();
    System.out.println(vals.pop());
}

}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage