abc123456789045
abc123456789045
2020-10-14 17:15
采纳率: 50%
浏览 45

初学者打代码出现问题,希望大佬可以帮助

package testa;

public class SimpleCalculator {
    private static float value1;
    private static SimpleCalculator claculator;
    private float value2;

    public SimpleCalculator(float value12, float value22) {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        float valuel=0;
        float value2=0;
        if(args.length>=2) {
            value1=  Float.parseFloat(args[0]);
            value2=Float.parseFloat(args[1]);
        }
        else {
            System.out.println("请输入俩个操作数");
            return;

        }
        SimpleCalculator calculator = new SimpleCalculator(value1,value2);
        claculator.printResult();
    }
    public void SimpleCalculator1(float value1,float value2) {
        this.value1 = value1;
        this.value2 =value2;

    }
    public void printResult() {
        float addResult = value1 + value2;
        float subResult = value1 - value2;
        float multiResult = value1 * value2;
        float divResult = value1 / value2;
        System.out.println(value1 + "+" +value2+"="+addResult);
        System.out.println(value1 + "-" +value2+"="+subResult);
        System.out.println(value1 + "*" +value2+"="+multiResult);
        System.out.println(value1 + "/" +value2+"="+divResult);
    }



}


# ```而在Arguments中输入11,    11
![图片说明](https://img-ask.csdn.net/upload/202010/14/1602666817_862362.jpg)
运行结果![图片说明](https://img-ask.csdn.net/upload/202010/14/1602666842_456161.jpg)
代码没有出现错误标志
![图片说明](https://img-ask.csdn.net/upload/202010/14/1602666928_554286.jpg)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • qq_36911145
    封印di恶魔 2020-10-14 17:41
    已采纳

    claculator 没有初始化,所以调用printResult方法时报空指针
    这样改应该就可以了

    private static SimpleCalculator claculator = new SimpleCalculator();
    

    图片说明

    点赞 评论

相关推荐