Calculate average sale of the week in Java
By: Paawan Chaudhary Printer Friendly Format
This java program accepts value of apple sales for each day of the week (using array of type float) and then, calculates the average sale of the week.
import java.lang.*;
import java.io.*;
class q7Apple
{
public static void main(String args[]) throws IOException
{
double avg;
float sum=0;
float sales[]=new float[7];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i=1;i<=7;i++)
{
System.out.println ("Enter sales for day"+i+" of week =");
sales[i-1] = Float.parseFloat(br.readLine());
sum=sum+sales[i-1];
}
System.out.println ("Sum = "+sum);
avg=sum/7;
System.out.println ("Average sale of week="+avg);
}
}
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Archived Comments
1. Thanks a lot !
View Tutorial By: Kalander bava ta at 2012-11-04 08:07:15
2. I will appreciate if you can give me a sample Java
View Tutorial By: Momod Aliyu at 2015-10-27 13:00:43