DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Posts
    16

    Exclamation Command Line Argument : 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 ?

    Thanks,
    Rohan Chandane

  2. #2
    Join Date
    Mar 2006
    Location
    England
    Posts
    10
    In MS-DOS, the asterisk * is a special character that refers to files in the current directory. Hence, the arguments 6 2 * will simply return 6, then 2, then the list of files in the current (working) directory. Quoting the * character on its own doesn't seen to work. However, you could quote everything, and run e.g. java CmdOperator "6 2 *". In this case, the single string "6 2 *" is sent to your program which must then split it to get the 'actual' arguments.

  3. #3
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    else
    System.out.println("Enter Proper Operator!");
    }
    your missing a curly brace afer the else, im sure thats not your problem thoug, but i though i bring it to ur attention.

Similar Threads

  1. Command Line Argu: Why "*" not working with it?
    By rohan.chandane in forum Java
    Replies: 1
    Last Post: 03-22-2006, 04:40 PM
  2. They created J#, why couldn't they do VB#?
    By Thomas Eyde in forum .NET
    Replies: 290
    Last Post: 12-22-2001, 02:13 PM
  3. Replies: 1
    Last Post: 12-05-2001, 06:12 AM
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links