Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions: Create a simple command line program to calculate the average of a

ID: 3549535 • Letter: I

Question

Instructions: Create a simple command line program to calculate the average of a variable quantity of integers that are passed as an argument when the program is called. This uses the argv array from main - you should not use "scanf" or "cin" functions to complete this project. When the program is launched, have it display a welcome message. Also make sure to have the program display a help message if the user forgets to give any integers as the argument. The below examples demonstrate the program on a Windows system. If you use a Mac or Linux your program very likely will not have the

Explanation / Answer

public class Average

{

static int sum =0;

static float average = 0;

public static void main(String[] args)

{

if(args.length == 0){

System.out.println("Welcome to the Average Program. It is very average really."+ " " +""

+ "Usage: java Average X ( X is 1 or more integers )");

}else{

for(int i=0; i< args.length;i++)

sum = sum + Integer.parseInt(args[i]);

average = sum / args.length;

System.out.println("Welcome to the Average Program. It is very average really."+ " " +""

+ "The average is:" + average);

}

}

}