Question
so i have this method it's half written and i'm having a terrible time understanding how to complete the operands can someone help me complete
so i have this method it's half written and i'm having a terrible time understanding how to complete the operands can someone help me complete the rest of the switch cases for +, - , * , / in java
rivate static double calculateSpacedPostfix(String postfixSpaced) {
Scanner scan = new Scanner(postfixSpaced);
StackInterface
while(scan.hasNext()) {
String token = scan.next();
switch(token) {
case "+":
double result = 0;
while(operands.peek() != null){
result += operands.pop();
}
break;
case "(":
break;
case ")":
break;
default:
double value = Double.parseDouble(token);
operands.push(value); // Put each operand on the stack
}
}
scan.close();
return 0;
}
}
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