• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

what will the o/p for this ...

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]);
}
}
}
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can tell what do you mean by o/p?
thanks.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic