import java.util.Scanner;public class PrefixSolver { public static int result; public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a prefix notation: "); result = 0; System.out.println("Result: "+eval(in.next())); } public static int eval(String prefix) { int op1, op2;//, result = 0; char ch = prefix.charAt(0); if (ch >= '0' && ch <= '9') { result += (ch-'0'); return result; } else { op1 = eval(prefix.substring(1,prefix.length())); op2 = eval(prefix.substring(1,prefix.length())); switch (ch) { case '+': result += (op1+op2); break; case '-': result += (op1-op2); break; case '*': result += (op1*op2); break; case '/': result += (op1/op2); break; } } return result; }}