-
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
-
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.
-
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
-
By rohan.chandane in forum Java
Replies: 1
Last Post: 03-22-2006, 04:40 PM
-
By Thomas Eyde in forum .NET
Replies: 290
Last Post: 12-22-2001, 02:13 PM
-
Replies: 1
Last Post: 12-05-2001, 06:12 AM
-
By rahul phatak rahulphatak in forum ASP.NET
Replies: 0
Last Post: 06-01-2000, 05:41 PM
-
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
Forum Rules
|
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
|
Bookmarks