前缀表达式"/>
算法训练 前缀表达式
代码如下:
package ALGO_92;
import java.util.Scanner;
public class Main {public static int add(int a,int b){return a+b;}public static int sub(int a,int b){return a-b;}public static int mul(int a,int b){return a*b;}public static int div(int a,int b){return a/b;}public static void main(String[] args) {Scanner cin=new Scanner(System.in);char c=cin.next().charAt(0);int a=cin.nextInt();int b=cin.nextInt();int res=0;switch(c){case '+':res=add(a,b);break;case '-':res=sub(a,b);break;case '*':res=mul(a,b);break;case '/':res=div(a,b);break;}System.out.print(res);}
}
更多推荐
算法训练 前缀表达式
发布评论