aspose file tools*
The moose likes Beginning Java and the fly likes what will the o/p for this ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what will the o/p for this ..." Watch "what will the o/p for this ..." New topic
Author

what will the o/p for this ...

arun sharma
Greenhorn

Joined: Jul 02, 2003
Posts: 19
Hi friends;
Can u explain why the o/p of this program is like this:
class Test{
public static void main(String args[]){
for(int nElement = 0 ; nElement < args.length ; nElement++)
{
System.out.println("File: "+args [nElement]);
}
}
}
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
can tell what do you mean by o/p?
thanks.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you start a Java program from the command line with a few arguments then the JVM invokes the main method you show in your example, with the parameters in the args. So if you type:
java MyClass able baker charlie
then args[0] is able, args[1] is baker, args[2] is charlie. The loop in your program will print the arguments out on one line each.
Your example includes the word "File:" so I'd guess your program is expecting a list of files as arguments. If a filename includes spaces you'll have to type it in quotes so it is read as one argument and not two or three.
java MyClass "c:\program files\my file.txt"
Is that the kind of thing you were asking? Sorry if I backed up over stuff you already knew.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, arun!
Can u explain why the o/p of this program is like this:
What is the output? And do you have any ideas on why it might be that way?
can tell what do you mean by o/p?
Namaste, "o/p" likely means "output".
[ July 04, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what will the o/p for this ...
 
Similar Threads
question on maximum value of primitive data type
float result
forward referencing
Will it work....
What is your answer?