POJ2694逆波兰

import java.util.Scanner;

//逆波兰
public class POJ2694 {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.format(“%.6f”, calc());
}
private static double calc() {
String atom = scanner.next();
switch (atom.charAt(0)) {
case ‘+’:
return calc() + calc();
case ‘-‘:
return calc() - calc();
case ‘*’:
return calc() * calc();
case ‘/’:
return calc() / calc();
default:
return Double.parseDouble(atom);
}
}
}

你可能感兴趣的:(数据结构,算法)