This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "query" Watch "query" New topic
Author

query

prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67
Hi,

I am not getting the output for this program. It is compiling but did not get any output.


class test {
public static void main(String args[]) {
if(args.length > 0)
System.out.println(args.length);
}
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

It will only print something if you give it an argument -- i.e.,

java test Hello

will print "1". The argument list includes neither "java" nor the name of the class.


[Jess in Action][AskingGoodQuestions]
Anandh Ramesh
Ranch Hand

Joined: Dec 15, 2004
Posts: 61
hi

the part "String[] args" actually refers to command-line arguments. so, if you execute it without one, the value of args.length() is zero. since you have asked the code to print any length greater than zero, this is not printed. if you modify your code, i.e., remove your 'if' condition, you will get an output of 0. try giving any command-line arguments, and the code will print the number of arguments given.

all the best,
Anandh


cheers,<br />Anandh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: query
 
Similar Threads
operators
Enthuware question
string concatenation
Strange output
how to modify this program to get asending order integers?