[ Write a Program to input 10 numbers into an integer array and display those numbers which are less then its average.
Program Code :
import java.util.*;
class Less_Avg
{
public static void main(String args[])
{
int i,sum=0; double avg=0;
int n[]=new int[10];
Scanner sc=new Scanner(System.in);
//Accepting 10 Array Element
for (i=0;i<10;i++)
{
System.out.print("Enter the Array Element = ");
n[i]=sc.nextInt();
}
for (i=0;i<10;i++)
{
sum=sum+n[i]; // SUM of Array Element
}
avg=sum/10; // Calculating Averege of 10 number
System.out.println("Average = "+avg);
System.out.println("Array Element Which are less then Average :-");
for (i=0;i<10;i++)
{
if(n[i]<avg) //Checking Each Array Element is Less then Average or Not
System.out.println(n[i]);
}
}
}
No comments