Sum argument inputs - Java Object Oriented Design

Java examples for Object Oriented Design:main method

Description

Sum argument inputs

Demo Code

public class Main {
    public static void main(String[] arguments) {
        int sum = 0;

        if (arguments.length > 0) {
            for (int i = 0; i < arguments.length; i++) {
                sum += Integer.parseInt(arguments[i]);
            }//from  w  w w  .j  a  va  2 s  .  c  o m
            System.out.println("Sum is: " + sum);
            System.out.println("Average is: " +
                (float)sum / arguments.length);
        }
    }
}

Related Tutorials