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
  • 402
  • 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
  • 31,563
  • 8
  • 67
  • 95
3

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

giri
  • 24,958
  • 61
  • 134
  • 175
0

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

lukastymo
  • 23,992
  • 12
  • 50
  • 66