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

Create a simple command line Java program to calculate the average of a variable

ID: 3849519 • Letter: C

Question

Create a simple command line Java program to calculate the average of a variable that is set to be an array that are passed as an argument when the program is called. This uses the args array from main - you should not create or use a scanner object. The actual calculation of the average, finding the highest and lowest values needs to be conducted within multiple static methods. When the program is launched, have it display a welcome message. Also make sure to have the program the display a help message of the user forgets to give any integers.

Explanation / Answer

import java.lang.*;
public class Commandline
{
public static int min(String arg[])
{
int small=arg[0];
for(int i=0;i<arg.length;i++)
{
if(small<arg[i])
small=arg[i];
}
return small;
}
public static int max(String arg[])
{
int large=arg[0];
for(int i=0;i<arg.length;i++)
{
if(large>arg[i])
large=arg[i];
}
return large;
}
public static void main(String[] args)
{
System.out.println("Welcome");
int value=0,s=0,l=0;
System.out.println("You Gave The Array size as"+args.length);
for(int i = 0; i < args.length; i++)
{
System.out.println("Reading "+i+" Position Value");
args[i]=i;
}
System.out.println("calling Min Method");
s=min(args);
System.out.println("calling Max Method");
l=max(args);
int avg=(s+l)/2;
System.out.println("The Average given number is"+avg);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote