java - args.length and command line arguments -


i got confused how use args.length, have coded here:

public static void main(string[] args) {     int [] = new int[args.length];      for(int = 0;i<args.length;i++) {         system.out.print(a[i]);     } } 

the printout 0 no matter value put in command line arguments, think confused args.length args[0], explain? thank you.

int array initialized 0 (all members zero) default, see 4.12.5. initial values of variables:

each class variable, instance variable, or array component initialized default value when created ...

for type int, default value zero, is, 0.

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

did try this?

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

args contains command line arguments passed program.
args.length length of arguments. example if run:

java myjavaprogram first second 

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


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -