The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

HelloWorld program

Posted by David Lowe on September 24, 2000 at 9:01 PM

I've never programmed before in Java, actually I've never programmed, period. I'm attempting to teach myself. I was looking at the HelloWorld program below:

// A simple program to print out the string "HelloWorld".

public class HelloWorld
{

/* Applications always execute the main method of
the class first.

@param args[] contains the command line arguments.
*/

public static void main(String args[])
{
System.out.println("Hello world!");
}

}

Suppose I wanted the program to echo the number of runtime arguments. For instance, if I type java HelloWorld this is a test
the output should be 4 because there are four arguments passed to the program. (The name of the program is HelloWorld)

What if I wanted the program to echo the factorial of the number of arguments to the program. For instance, if I type java HelloWorld this is a test the output should be 24 (= 4 x 3x 2 x 1), which is the factorial of 4.

What changes would I have to make to the above code. I tried the following but it gives a blank answer:

/*A simple program to echo the number of runtime
arguments*/

public class HelloWorld
{
public static void main (String args[])
{
for (int i = 0; i < args.length; i++)
{
System.out.print(args[i]+" ");
}
System.out.println(" ");
}
}


Thanks in advance.






Replies:
  • sample code... Jeff Kinsey September 25, 2000 at 12:38 PM (1)
    • dd ddd November 15, 2000 at 9:53 PM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us