Write a program in java which enters three number using command line arguments and print sum and average of the number.
class SumAVg_cmd
{
public static void main(String[] args)
{
String name;
// Check if at least one argument is passed
if (args.length > 0)
{
int a,b,c,sum=0;
double avg=0.0;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
sum=a+b+c;
avg=sum/3.0;
System.out.println("Sum is = " +sum+" and Average is = "+avg);
}
else
{
System.out.println("Please provide your name as a command line argument.");
}
}
}
Output:



0 Comments