Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n;
System.out.print("Enter size of array: ");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
for (int i = 0; i < a.length; i++) {
System.out.print("Enter " + (i + 1) + " element: ");
a[i] = sc.nextInt();
}
int sum = 0;
for (int j = 0; j < a.length; j++) {
sum = sum + a[j];
}
int mean;
mean = sum / a.length;
System.out.println("\nMean = " + mean);
}
}
Output:
Tags:
Java Programs