Write a java program that reads ten numbers from the user in an array and then prints the array, Maximum, Minimum, Sum and average of the enfered array.
Write a java
Plesiosaurs provide a scree
Java Program-
import java.util.Scanner;
public class Array
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
//creates an array in the memory of length 10
int[] array = new int[10];
for(int i=0; i<10; i++)
{
//reading array elements from the user
array[i]=sc.nextInt();
}
System.out.println("Array elements are: ");
int sum = 0;
int max,min,avg;
max = min = array[0];
// accessing array elements using the for loop
for (int i=0; i<10; i++)
{
sum += array[i];
if(array[i] > max)
max = array[i];
else if (array[i] < min)
min = array[i];
System.out.print(array[i]);
}
// calculating Average
avg=sum/10;
// printting max, min, sum Average
System.out.println(" ");
System.out.println(" Maximum : " + max);
System.out.println(" Minimum : " + min);
System.out.println(" Sum : " + sum);
System.out.println(" Average : " + avg);
}
}
Step by step
Solved in 2 steps with 1 images