Question:
Java command line arguments?
2011-03-16 20:43:31 UTC
My assignment for class is

Write an application that uses an enhanced for statment to sum the double values passed by the command-line arguments

and i have NO IDEA what that means
can someone wright some code and then explain to me what in the world this means :)
thanks
Four answers:
modulo_function
2011-03-16 21:27:24 UTC
The values that you put on the command line will be stored in the string array that main gets.



public static void main(String[] args)



args has the command line arguments. Now you just need to convert them to doubles:



double[] values = new double[args.length()];



convert them:

for( int k=0; k
...values[k] = Double.parseDouble(args[k]);

}



That's how you get the command line arguments in the string array and convert them. Now it's up to you to write the loop to sum them.
lavalle
2016-11-13 12:01:13 UTC
while you're launching from an IDE, like JCreator, Netbeans, Eclipse... those are actually not the CommandLine invocation of a Java software. interior the previous days we made a folder, used Notepad and typed the code such as you instruct. Then... >$ cd /myPrograms/Java /myPrograms/Java >$ javac CLCDemo.java /myPrograms/Java >$ java CLCDemo.java one-potato 2-potato 3-potato greater and it might output the 4 args edit:::::::::::: I basically now copied your keystrokes, made a document CLDemo.java consumer@consumer-computing device computing gadget: ~$ cd '/homestead/consumer/computing device computing gadget/testCmmdline' consumer@consumer-computing device computing gadget: ~/computing device computing gadget/testCmmdline$ javac CLDemo.java consumer@consumer-computing device computing gadget: ~/computing device computing gadget/testCmmdline$ java CLDemo one 2 3 There are 3 command-line arguments. they're: arg[0]: one arg[a million]: 2 arg[2]: 3 consumer@consumer-computing device computing gadget:~/computing device computing gadget/testCmmdlin...
Blackcompe
2011-03-16 21:07:28 UTC
See http://download.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html. The first code snippet pretty much solves your homework problem. Use doubles instead of strings.
2011-03-16 21:35:11 UTC
you have to pass arguments from command prompt

this is simple program here you can find more java program including this


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...