Results 1 to 4 of 4
  1. #1
    internet10 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default Help With Calculator Pl0x

    I am new to java, and am attempting to learn it. So far I am trying to make a simple command prompt argument calculator, and it isnt working.

    Here's my code

    public class calculator
    {
    public static void main( String[] args)
    {
    int i = Integer.parseInt(args[0]) ;
    int y = Integer.parseInt(args[2]) ;
    String modi =(args[1]) ;
    int ans = 0;
    if( args.length !=3)
    {
    System.out.println("wrong number of arguments") ;
    return;
    }
    if (modi=="+")
    {
    ans =(i + y );
    System.out.println(ans) ;
    }
    else if (modi=="-")
    {
    ans = (i - y );
    System.out.println(ans ) ;
    }
    else if (modi=="/")
    {
    ans = (i / y );
    System.out.println(ans ) ;
    }
    else if (modi=="x")
    {
    ans = (i*y );
    System.out.println(ans ) ;
    }
    else
    {
    System.out.println("Failure In Arguments") ;
    }
    }
    }

    I'm trying to use 56 x 2 for the arguments.
    My guess is that I'm missing something simple, but i can't find it.
    I have tried sending the arguments through the command prompt and eclipse and neither work.
    Any correction would be helpful.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    else if (modi=="x") -->
    else if (modi.equals("x"))

    Java: String Comparison

  4. #4
    internet10 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Calculator
    By Moshe22 in forum New To Java
    Replies: 8
    Last Post: 01-17-2011, 05:29 AM
  2. Help in a calculator
    By Ayannie in forum New To Java
    Replies: 6
    Last Post: 01-04-2011, 08:21 PM
  3. Calculator
    By water in forum AWT / Swing
    Replies: 4
    Last Post: 09-23-2009, 06:00 AM
  4. help with calculator
    By kalibballer in forum New To Java
    Replies: 8
    Last Post: 04-01-2009, 12:57 PM
  5. Calculator help.
    By madkidd02 in forum New To Java
    Replies: 2
    Last Post: 10-25-2008, 07:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •