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
Post a Comment