calculate sum and average using command line argument -programmingraja

 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("");

}

}

OUTPUT:




Post a Comment

0 Comments