关于计算...重新发布 [英] About Calculate... Repost

查看:80
本文介绍了关于计算...重新发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.util.Scanner;
public class Calculate
{
    static Scanner in = new Scanner(System.in);

    public static void main(String [] args)
    {
        String sign;
        int num1;
        int num2;
        int num3;
        int ans;
        System.out.print("Enter your Calculations => \n");
        sign = in.nextLine();

        if(args.Length == 3)
        {
            num1 = Integer.parseInt(args[0]);
            sign = (args [1].equal("1"));
            num2 = Integer.parseInt(args[2]);
            num3 = Integer.parseInt(args[3]);
            ans = num1 + num2;
            ans = num1 - num2;
            ans = num1 / num2;
            System.out.println("Answer = "+ ans);
        }
        else if(args[1].equal("+")) 
        {
            ans = num1 + num2;
            System.out.println("num1 "+ "num2 " = ans);
        }
        else if(args[2].equal("-")) 
        {
            ans = num1 - num2;
            System.out.println("num1 "- "num2 "= ans);
        }
        else if(args[3].equal("/")) 
        {
            ans = num1 / num2;
            System.out.println("num1 "/ "num "= ans);
        }
        else if("Do it again => Calculate arg1, arg2, arg3");
    }
}
}

推荐答案

我并没有做很多JavaScript,但是最后一个if/else语句看起来很可疑.
I''ve not done a lot of javascript, but that last if/else statement looks suspect.


这是此问题的转发 [ ^ ],该问题已得到更完整的解答.
This is a repost of this question[^], which has been answered more fully.


这篇关于关于计算...重新发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆