首页 > 解决方案 > 为什么在 * 作为参数时会出错

问题描述

class Simcal1{
    public static void main(String []args){

        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[2]);
        char ch = args[1].charAt(0);

        switch(ch){
            case '+':System.out.println("Addition :" + (a+b) );   
                 break;
            case '-':System.out.println("Subtraction :" + (a-b) );
                 break;
            case '/':System.out.println("Division :"+ (a/b) );   
                 break;
            case '*':System.out.println("Multification :"+ (a*b) );
                 break;
            default:System.out.println("Enter valid choice");
        }
    }
}

在此处输入图像描述

为什么我在给出 5 * 5 作为参数时出现错误?但在其他情况下为 4 + 5 它工作正常。

标签: java

解决方案


推荐阅读