Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
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");
    }
}
}
Posted
Updated 19-Jan-11 3:40am
v4

I've not done a lot of javascript, but that last if/else statement looks suspect.
 
Share this answer
 
Comments
Khalil Adam 19-Jan-11 6:29am    
thanks alot John,but what did u think l should replace instead of the last if/else statement?
Richard MacCutchan 19-Jan-11 9:41am    
It's all suspect, and it's Java, not Javascript. More answers in the Java forum.
This is a repost of this question[^], which has been answered more fully.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900