Question
java calculator program I need help adding these excemptions in my postfix method -4 2 + - 1 * 1 + = Exception caught: missing
java calculator program
I need help adding these excemptions in my postfix method
-4 2 + - 1 * 1 + = Exception caught: missing operand -3 5 = Exception caught: missing operator
public static double evalPostfix(String s) throws IllegalArgumentException { Stack
stack.push(Double.parseDouble(sbuf.toString())); } // If the scanned character is an operator, pop two // elements from stack apply the operator else { double val1 = stack.pop(); double val2 = stack.pop(); switch(tokens[i-1]) { case '+': stack.push(val2+val1); break; case '-': stack.push(val2- val1); break; case '/': stack.push(val2/val1); break; case '*': stack.push(val2*val1); break; default : System.out.println("Invalid token"); break; } } } return stack.pop(); } public static boolean isNum(String strNum) { boolean ret = true; try {
Double.parseDouble(strNum);
}catch (NumberFormatException e) { ret = false; } return ret; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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