Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output of 'args' gives some wierd info...?

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i give
System.out.println(args);//ToArgs is the name of the prog.
in my code i get some wierd results during my interpretation.....
ie. the compile works fine....the interpretation gives me....
d:\>java ToArgs
[Ljava.lang.String;@273dc3
does any one know what that output means?
good luck,
ak.
 
Thandapani Saravanan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember the argument to main method is an array of Strings. When you try print an array as such, that is output you get. (it calls Object's toString())
If you want to print all entries try printing them one by one:
for(int i=0;i<args.length;i++)>
System.out.println(args[i]);
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ljava.lang.String;@273dc3

The @273dc3 is the address of the array args[].
Marilyn
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if i want to put a condition check on the args. passed.
ie. Say if a persson passes arguments then print them else say no args. passed
eg.
if (args==true)
print(args[0], args[1]); etc.
else print(No args passed);
something likethe pseudocode eg. shown above.
ak.
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could try something like:
<pre>class TestArgs {
public static void main ( String[] args ) {

if ( args.length > 0 ) {
for ( int i = 0; i < args.length; i++ ) {
System.out.println( args[i] );
}
} else {
System.out.println("No arguments");
}
}
}
</pre>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic