Command Line Argu: Why "*" not working with it?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Command Line Argu: Why "*" not working with it?

  1. #1
    Join Date
    Mar 2006
    Posts
    16

    Command Line Argu: Why "*" not working with it?

    Hi Friendz,

    I just written a program which Accept two nos. and an operator on command line and print the result.

    Here is the code -

    class CmdOperator
    {
    public static void main(String[] a)
    {
    int num1,num2,res;
    String opr;

    if (a.length > 0)
    {
    num1 = Integer.parseInt(a[0]);
    num2 = Integer.parseInt(a[1]);
    opr = a[2];
    if(opr.equals("+"))
    {
    System.out.println("num1 + num2 = " + (num1+num2));
    }
    else if(opr.equals("-"))
    {
    System.out.println("num1 - num2 = " + (num1-num2));
    }
    else if(opr.equals("*"))
    {
    System.out.println("num1 * num2 = " + (num1*num2));
    }
    else if(opr.equals("/"))
    {
    System.out.println("num1 / num2 = " + (num1/num2));
    }
    else
    System.out.println("Enter Proper Operator!");
    }
    else
    {
    System.out.println("Please Enter Numbers");
    }
    }
    }


    ------

    here are the code output -

    output 1
    C:\>java CmdOperator 6 2 +
    num1 + num2 = 8

    output 1
    C:\>java CmdOperator 6 2 -
    num1 + num2 = 4

    output 1
    C:\>java CmdOperator 6 2 /
    num1 + num2 = 3

    output 1
    C:\>java CmdOperator 6 2 *
    Enter Proper Operator!

    The Question is Why it is not understanding the "*" operator?

  2. #2
    Join Date
    Mar 2006
    Location
    Greenville, SC USA
    Posts
    2
    "*" is being interpreted by the "cmd" shell and expanded into a dir listing prior to passing it to you program as an argument...
    I don't know how to fix that in windows, but in Linux/Unix:
    # java CmdOperator '6' '2' '*'
    will produce your desired result.

Similar Threads

  1. Replies: 1
    Last Post: 12-05-2001, 06:12 AM
  2. changing working dir in Java
    By Jim in forum Java
    Replies: 1
    Last Post: 02-18-2001, 01:58 PM
  3. focus() & select() not working
    By Craig in forum Web
    Replies: 7
    Last Post: 02-08-2001, 02:16 PM
  4. VSS:sharing same working folder without multiple checkouts
    By rahul phatak rahulphatak in forum ASP.NET
    Replies: 0
    Last Post: 06-01-2000, 05:41 PM
  5. Sysinfo not working GetSystemPowerStatus not working
    By Thomas Hauff in forum VB Classic
    Replies: 0
    Last Post: 04-08-2000, 10:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center