w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
args.length and command line arguments

int array is initialized to zero (all members will be zero) by default, see 4.12.5. Initial Values of Variables:

Each class variable, instance variable, or array component is initialized with a default value when it is created ...

For type int, the default value is zero, that is, 0.

You're printing the value of the array, hence you're getting 0.

Did you try to do this?

for(int i = 0;i<args.length;i++) {
     System.out.print(args[i]);
}

args contains the command line arguments that are passed to the program.
args.length is the length of the arguments. For example if you run:

java myJavaProgram first second

args.length will be 2 and it'll contain ["first", "second"].





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.