/* 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");
}
}Java
Calculate Average of 'N' Numbers Using Java Program

Written by
View ProfileSenthilvelan Sambamoorthy
Senthilvelan Sambamoorthy is working as a Professor in Department of Master of Computer Applications, Paavai Engineering College, Namakkal, Tamilnadu, India, He is Masters in Computers Applications. Having 18+ years of experience and his area of interest is Java, JSP, Servlet, J2EE, C#, PHP, Python ASP.NET, SQL Server and etc.
