/* AVERAGE CALCULATION OF 'N' NUMBERS */
import java.io.*;
import java.text.*;
class ssva17
{
public static void main(String arg[]) throws IOException
{
int i,n;
double a[]=new double[20];
double tot=0,avg;
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
System.out.println(" AVERAGE CALCULATION ");
System.out.println(" ------- ----------- ");
System.out.print("\nENTER HOW MANY NUMBERS : ");
n=Integer.parseInt(obj.readLine());
NumberFormat nf=NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
System.out.println("\nENTER THE NUMBERS\n");
for(i=1;i<=n;i++)
{
a[i]=Double.parseDouble(obj.readLine());
tot+=a[i];
}
System.out.println("\nTOTAL IS : "+nf.format(tot));
avg=tot/n;
System.out.println("\nTHE AVERAGE IS : "+nf.format(avg));
System.out.println("\n");
}
}In this program, easy to understand to calculate average calculation of 'N' numbers using Java Program.
