Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Calculate Average Of 'N' Numbers Using Java Program
WhatsApp
Senthilvelan Sambamoorthy
Aug 13
2016
1.1
k
0
0
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
Up Next
Calculate Average Of 'N' Numbers Using Java Program