Wednesday, 8 August 2018

COMMAND LINE ARGUMENTS



Command Line arguments are parameters that are supplied to the application program at the
time of invoking it for execution.
/* Program to find the average of 3 numbers */
class average
{
public static void main(String []args)
{
int s1=Integer.parseInt(args[0]);
int s2=Integer.parseInt(args[1]);
int s3=Integer.parseInt(args[2]);
int total=s1+s2+s3;
double avg=total/4;
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
System.out.println("Total= " +total);
System.out.println("Average="+avg);
}
}
Output:
E:\javaprograms>javac average.java
E:\javaprograms>java average 50 60 70
50
60
70
Total= 180
Average=45.0

No comments: