-4

java Application 23 * 2

public static void main(String[] args){

    System.out.println(args.length);
}

output: 7

why?

Filburt
  • 16,951
  • 12
  • 63
  • 111
Ajit Singh
  • 11
  • 2

1 Answers1

1

On Windows, you would get what you're expecting.

On Linux, the command shell is applying wildcard expansion, replacing the * with names of all the files in the current directory.

To prevent wildcard expansion, quote the parameter (from Stop shell wildcard character expansion?):

java Application 23 '*' 2
Community
  • 1
  • 1
Andreas
  • 147,606
  • 10
  • 133
  • 220
  • 1
    or possibly the OP wants java Application '23 * 2' - that is, a single argument to main – FredK Dec 16 '15 at 17:05