0% found this document useful (0 votes)
58 views

Given A List of Numbers Find The Largest, Smallest, and Average of All The Elements in An Array

The document describes a Java program that takes in an array of numbers from the user, loops through the array to find the largest number, smallest number, and average. It prints out the largest, smallest, and average values.

Uploaded by

Niranjan Sah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Given A List of Numbers Find The Largest, Smallest, and Average of All The Elements in An Array

The document describes a Java program that takes in an array of numbers from the user, loops through the array to find the largest number, smallest number, and average. It prints out the largest, smallest, and average values.

Uploaded by

Niranjan Sah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Given a list of numbers find the largest, smallest, and average of all the

elements in an array.
import java.util.Scanner;

public class Average {

public static void main(String[] args) {


Scanner s=new Scanner(System.in);
System.out.println("Enter the size of array=");
int n=s.nextInt();
int Arr[]=new int[n];
System.out.println("Enter the array elements:");
for(int i=0;i<n;i++)
Arr[i]=s.nextInt();
int len=Arr.length;
int sum = 0;
int min = Arr[0];
int max = Arr[0];
int avg;

for(int i = 0; i < len; i++)


{
sum += Arr[i];

if(Arr[i] < min)


min = Arr[i];
else if(Arr[i] > max)
max = Arr[i];
}

avg = sum /len;

System.out.println("Largest elements is "+min);


System.out.println("Smallest elements is "+max);
System.out.println("Average of array is "+avg);

Output:

You might also like