Command Line Arguments in Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Command Line Arguments in Java

Share This

Most of the time, developers write programs that interact with the user through standard input and output streams at run-time. But standard inputs and outputs do not solve all the requirements of the users. Sometimes, we need to pass data at the time of entering a run command for the program. The data which are passed to a program in this way are known as command-line arguments.

Note that the command line arguments are passed to the main method as arguments.

CommandLineArgs.java
public class CommandLineArgs { public static void main(String[] args) { int counter = 0; double sum = 0.0; for (String s : args) { sum += Double.parseDouble(s); counter++; } System.out.println("The sum of elements is : " + sum); System.out.println("Average of the elements is : " + sum / counter); } }



Happy Exploring!

No comments:

Post a Comment