New Want to Write for Computaholics ? if Yes Contact us at "contact@computaholics.in"

Program to find sum,average,minimum and maximum of N numbers using command line arguments

Program to find sum,average,minimum and maximum of N numbers using command line arguments program in java:-

To get the average of the numbers you have to build the sum of them and then divide through the number of arguments.

class Average
{
public static void main(String args[])
{
int sum=0,i,count=0,max,min,n;
float avg;
if (args.length == 0)
System.out.println(“Argument is expected”);
else
{
i = args.length;
System.out.println(“Number of arguments is ” +i);
max = Integer.parseInt(args[0]);
min = Integer.parseInt(args[0]);

System.out.println(“first argument is” +args[0]);

System.out.println(“Second argument is” +args[1]);

//System.out.println(“Third argument is” +args[2]);
while(count < i)
{
n = Integer.parseInt(args[count]);
sum += n;
if(min > n)
min = n;
if (max < n)
max = n;
count += 1;
}
avg = sum/i;
System.out.println(“The sum is ” +sum);
System.out.println(“The average is ” +avg);
System.out.println(“Maximum is ” +max);
System.out.println(“Minimum is ” +min);
}
}
}
Copyright © C Program | Java | OpenGL Programming | Hadoop at Computaholics