About 500,000 results
Open links in new tab
  1. Java Program to Find Sum and Average of All Elements in an Array

    This is a Java Program to Calculate Sum & Average of an Array. Enter size of array and then enter all the elements of that array. Now using for loop we calculate sum of elements of array and hence we divide it by number of elements in array to get average. Here is the source code of the Java Program to Calculate Sum & Average of an Array.

  2. java - calculate average with user input - Stack Overflow

    Jun 5, 2012 · I'm writing a program to calculate average with user input. static Scanner input = new Scanner (System.in); public static void main (String[] args) double i; double sum = 0; int count = 0; do. System.out.println("input"); i = input.nextDouble(); sum = sum + i; count++; }while (i != 0);

  3. java - Sum and average of values in an array - Stack Overflow

    Aug 21, 2016 · sum = sum + a[i]; //add the current value in variable sum with the element at ith position in array. Store the result in sum itself. double avg = (double) sum / 10; //Compute the average using the formula for average and store the result in a variable of type double (to retain numbers after decimal point).

  4. Find Sum and Average in a Java Array - Baeldung

    Aug 16, 2024 · In this quick tutorial, we’ll cover how to calculate the sum and average of the elements in an array using both Java standard loops and the Stream API. For simplicity, we’ll ignore the cases where the input array is null or empty.

  5. average - Java Averaging Program - Stack Overflow

    Oct 22, 2013 · Average avg = new Average(); System.out.println("The average is: " + avg.average(numb1, numb2)); at the end of your main method. Alternatively you can make the methods static: public static double average (int num1, int num2) { return (num1 + num2) / 2.0; } More info on constructors and static.

  6. Calculate the Sum and Average of Elements in an ArrayList in Java

    Feb 12, 2024 · In this article, we will see how we can sum and find the average of the ArrayList in Java. Methods to Calculate the Sum or Average of Elements in an ArrayList. Using Enhanced for loop; Using simple for-loop; Program to Calculate the Sum and Average of Elements in an ArrayList in Java Method 1: Using Enhanced for loop

  7. Java Program To Find the Sum and Average of an Array

    Mar 5, 2021 · Use a recursive function to calculate the sum and average of all the elements in an array. Return the average and sum of all the elements in an array. Print the average and sum of all the elements in an array.

  8. Java simple programs | Program of sum, average, area etc

    public static void main(String [] args) { . int firstNum = 1234; . int secondNum = 5678; . int sum = firstNum + secondNum; // Adding two number int avg = (firstNum + secondNum)/2; // Calculating average of two number . System.out.println("sum = " +sum); System.out.println("Average = " …

  9. Java 8 – Find sum and average of a List or ArrayList

    1. Java 8 – Find sum and average of a List. Use IntSummaryStatistics to find various parameters/statistics of a List like, Sum of all elements in a List using getSum() method which returns value in long-type; Average of all elements in a List using getAverage() method which returns value in double-type

  10. How to Find Maximum, Minimum, Sum, and Average of a List in Java 8

    Learn how to use Java 8 streams to efficiently find the maximum, minimum, sum, and average of a list with clear examples and best practices.

  11. Some results have been removed
Refresh