Home Answers Viewqa Java-Beginners Calculate sum and Average in java

 
 


Naulej kumar
Calculate sum and Average in java
1 Answer(s)      11 months ago
Posted in : Java Beginners

How to calculate sum and average in java program?

View Answers

June 8, 2012 at 6:52 PM


Example:-

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class AvarageTest {
    public static void main(String[] args) throws IOException {

        System.out.println("Input any No.");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String data = (String) br.readLine();
        int num = Integer.parseInt(data);
        int sum = 0;
        float avg = 0.0f;

        for (int i = 1; i <= num; i++) {
            sum = sum + i;
        }
        avg = sum / num;
        System.out.println("Sum- " + sum);
        System.out.println("Avg- " + avg);

    }
}

Output

Input any Value.

Description:- In this example we are calculating sum and average of n numbers. The given code accepts the numbers from the user using BufferedReader class. Then using the for loop, we have calculated the sum of all numbers. And after dividing the sum by the total number of numbers, we have determined the average of numbers.









Related Pages:
Calculate sum and Average in java
Calculate sum and Average in java  How to calculate sum and average.... Description:- In this example we are calculating sum and average of n numbers... the sum by the total number of numbers, we have determined the average of numbers
calculate average
calculate average   Design and write a java program to determine all three digit numbers such that the sum of the cubes of the digits is equal... and write a program and calculate your final average in this course. The details
calculate average
calculate average  Question 2 cont.d Test case c: home works/labs 10 9 9 9 10 10 9 9 10 10 9 9 10 test scores: 65 89 note, the program should work with different numbers of home works/labs
sum and average of grades
sum and average of grades  how to print a program which is sum and average of Korean (90), English(85), Mathematics(78), Biology(65), Chemistry(83
Calculate the Sum of three Numbers
Calculate the Sum of Three Numbers       This is simple java programming tutorial . In this section you will learn how to calculate the sum of three numbers by using three
Calculate an average Age of my Class?
Calculate an average Age of my Class?  average age of my class
Calculate sum of even and odd numbers in Java
Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum... numbers from the file and then calculate their sum. Here is the code
SQL Average Count
SQL Average Count       Average Count in SQL is used to count the aggregate sum of any field... example ,which helps you to calculate the average count of any records specified
Calculate Company's Sale using Java
Calculate Company's Sales Using Java In this section, you will learn how to calculate Company's sale. A company sales 3 items at different rates and details...); System.out.println("Average Weekly Sale per day= " + sum / 7
Mean - average
Java NotesMean - average Computing the arithmetic average (mean) can... sum = 0; // sum of all the elements for (int i=0; i<p.length; i++) { sum += p[i]; } return sum / p.length; }//end method mean Question
SQL Average Count
SQL Average Count       Average Count in SQL is used to count the aggregate sum of any field... example ,which helps you to calculate the average count of any records specified
Sum of Column in a Database Table
;    This section describes how we can calculate the sum... university where we need to calculate the sum of  numbers achieved... of that column of which we want to calculate the sum. If the statement gets processed
Class Average Program
condition for sum values. Then calculate the value this method "average... will learn how to use java program for displaying average value. The java instances... Class Average Program     
Sum of two Matrix
Sum of  two Matrix       In this section, we are going to calculate the sum of two matrix... to this. In this program we are going to calculate the sum of two matrix. To make this program
Student average
to maintain this status is to maintain an average not below 1.8. write a java program... should display the average grade of the student and would display the message...: 1.2 Enter number of units: 1 you got an average of 1.59 congratulation
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
how to print the average of each column of 2d n*m array using java
the content of file.now i want to calculate mean(average) of each column present...how to print the average of each column of 2d n*m array using java  ...++) { System.out.println("Sum of column: "+(i+1)+": "+column[i
Sum of integers
Sum of integers  A Java program that reads an integer value from the user and displays i) the sum of all even integers between 1 and the input value, both inclusive. ii) The sum of all odd integers between 1 and the input
JPA Sum Function
of JPQL (Java Persistence Query Language). The sum function to calculate the sum...;SELECT SUM(p.price) FROM Product p"); This query calculate... JPA Sum Function      
PHP Get Average - PHP
PHP Get Average  I am writing a method to calculate the average rating of the posted answers? can anyone help me with the method to calculate rating in PHP. In my code, we are providing maximum four options to the user to rate
Determine Average by removing Largest and Smallest Number
into a variable 'sum' which is further used in determining the average. Here is the code...[i]; } System.out.println("Final Score: " + sum); int average = sum / 8...Determine Average by removing Largest and Smallest Number In this section, you
C calculate sum of first and last element of array
C calculate sum of first and last element of array In this section, you will learn how to calculate sum of first and last element from the array of five... and the last number and determine their sum. Here is the code
Sum of a Number using Swing
Sum of a Number using Swing       In this section, you will learn how to sum of a number using swing... used in this application : 1. JFrame is used to  creating  java
Finding Average in JSP
; <% float grades[] = {98, 99, 100, 97, 78, 96}; float sum, average...++) { sum = grades[j] + sum; } average = sum...Finding Average in JSP      
Average
Average   I have created a file that reads in a text file for a combo box which are exams assignments and quizes. I then have a a textfield..., assignments, etc.) so I can have the average of each item. I then need to graph
Calculating Sum of two Multidim
that will calculate the sum of the matrix. To make this program run we need to declare two multidimensional array of type int. Firstly calculate the length... Sum of Multidimensional Arrays   
Sum database colum in java
Sum database colum in java  please i have two columns-col1 and col2... the database to sum the Items and display output so that it will be like... question what you have asked. select item, sum(quqantity) from `order` group
Using sum() in hibernate criteria.
Using sum() in hibernate criteria.  How to calculate sum() in hibernate criteria by using projection?   You can calculate sum of any...(employee); } } } Output: Hibernate: select sum
Sum of first n numbers
Sum of first n numbers  i want a simple java program which will show the sum of first n numbers....   import java.util.*; public class...=input.nextInt(); long sum=0; for(int i=1;i<=n;i++){ sum+=i
calculate size of array
calculate size of array  Is it possible to calculate the size of array using pointers in Java
Sum - JSP-Servlet
the total sum of items from database using Java servlet or Jsp and html form. It should display the affected rows and the total sum of all in a seperate column..., Sum Into Database Salary
sum of fibonacci series
sum of fibonacci series  Write a Java program to print Fibonacci series upto n and find their sum also. 0+1+1+2+3+5+8+13+21ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦=sum   Hi, Please see the thread Fibonacci program. Thanks
Highest average score among 25 students
again the grade) calculate average per student and will calculate the highest average among students who should be printed. how can i solve this problem...Highest average score among 25 students  a program that prompts
sum
sum  a program to find the sum of the alternative diagit of it ex- no=123456 sum=1+3+5=9
sum and avg function using HQL.
calculates sum of salary as- sum(emp.salary) and average of salary as- avg...sum and avg function using HQL.  How to use sum and avg function in HQL?   HQL supports many aggregate functions. Sum and avg are some
Java Sum of Digits
Java Sum of Digits In this Java Tutorial section, you will learn how to find the sum of multidigit number. For this purpose, we have allowed the user to enter... for Sum of Digits in Java: import java.util.*; class SumOfDigits { public
sum
; sum=sum+s; if(i==n){ System.out.print(s...+"+"); } System.out.print("\nSum of the series : "+sum
sum
sum
sum
sum
sum
sum
sum
sum
how to find the sum of integers in a string of sentence in java
how to find the sum of integers in a string of sentence in java  how to find the sum of integers in a string of sentence in java for e.g:--> abc d 2 3 21 the output should be 2+3+21=26
Week calculate start from friday
Week calculate start from friday  My problem is to calculate how many weeks have a month. Note that my weeks have to start on Friday! I have three..., because the week starts on Friday. Can anyone help me,...PLEASE? (Java
How to calculate area of rectangle
How to Calculate Area of Rectangle       In this section we will learn how to calculate area... with the complete java source code. Description of this program In this program
how to calculate max and min - RUP
how to calculate max and min  hye!i'm a new for the java and i want to ask a question . Could anyone help me to teach how to calculate the maximum and minimum using java language.  Hi friend, In Math class having two
1-2+5-10+17-26 sum the series - Java Beginners
1-2+5-10+17-26 sum the series  1-2+5-10+17-26 sum the series  Hey Ankit, Try the following code. public class SumOfSeries3 { /** * @param 'series' holds the series need to be printed */ StringBuffer

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.