-
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?
-
"*" 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
-
Replies: 1
Last Post: 12-05-2001, 06:12 AM
-
Replies: 1
Last Post: 02-18-2001, 01:58 PM
-
Replies: 7
Last Post: 02-08-2001, 02:16 PM
-
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|