Aim:- Write a program to calculate the sum of three numbers and their average using command line argument.
Software Used: - Notepad, command prompt
Coding: -
public class sumavg
{
public static void main(String args[])
{
int num1 , num2 , num3, sum;
double avg;
if (args.length == 3)
{
num1=Integer.parseInt(args[0]);
num2=Integer.parseInt(args[1]);
num3=Integer.parseInt(args[2]);
sum=num1 + num2 + num3;
avg= sum / 3;
System.out.println("Sum of Three Number is : " + sum);
System.out.println("Average of Three Number is :" + avg);
}
else
System.out.println("");
}
}
0 Comments
if you have any problem, please let me know