← All resources

Write a program to input an int array of size 'n' and print all those values that are greater than the average

import java.util.*;
public class Avg_great
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        int n;
        System.out.println("Enter the size of the array:");
        n = sc.nextInt();
        int a[] = new int[n], i, s=0;
        double avg;
        System.out.println("Enter "+n+" values for the array:");
        for(i=0;i<n;i++)
        {
            a[i] = sc.nextInt();
            s = s+a[i];
        }
        avg = (double)s/n;
        System.out.println("Values that are above the average: ");
        for(i=0;i<n;i++)
        {
            if(a[i]>avg)
            System.out.println(a[i]);
        }
    }
}