2

Possible Duplicate:
Problem of * in Command line argument

I've written a simple attempt at a small calculator which does 4 operators (+,-,* and /).

When I pass any other 3 operator to my program through the command line, "java Calc 4 + 4", it works. However, when I tried passing "4 * 4" I get a reference to a Class.class - why is this objectified instead of being handled as a normal string? What is happening here?

Is it something to do with the Windows command line using the * as wildcard? If so, how can I get around this?

For now, as a simple fix, I've written the operator multiplies as the character 'x'.

TIA

Community
  • 1
  • 1
Adam
  • 442
  • 1
  • 6
  • 18

3 Answers3

3

The shell replaces * with the list of the files in the current directory. Use single-quotes to pass the asterisk: '*'.

Maurice Perry
  • 32,610
  • 9
  • 70
  • 97
3

Try surrounding the * with quotes like "*". The * is a reserved symbol on the command line.

giri
  • 26,773
  • 63
  • 143
  • 176
0

Because asterisk is OS depends char which means all files, so you must escape asterisk

lukastymo
  • 26,145
  • 14
  • 53
  • 66