TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Calculate Average Of 'N' Numbers Using Java Program
Senthilvelan Sambamoorthy
Aug 13
2016
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
ssva17.rar
/* 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