How to find the total score and average score

public class Main { public static void main(String[] args) { int [] scores = {20, 30, 40, 50, 80}; int sum = 0; // Aggregation result for (int i = 0; i < scores.length; i++) { sum + = scores [i]; // Sum to the variable sum }

	int avg = sum / scores.length;

System.out.println ("total score:" + sum); System.out.println ("average score:" + avg);

}

}

Recommended Posts

How to find the total score and average score
How to find the average angle
Difference between Java and JavaScript (how to find the average)
How to find the tens and ones
How to find the total value, average value, etc. of a two-dimensional array (multidimensional array)-java
How to find the cause of the Ruby error
How to find the total number of pages when paging in Java
How to find the distance and angle between two points on a plane
[Ruby] How to find the sum of each digit
[Ruby] How to get the tens place and the ones place
How to run React and Rails on the same server
How to check the extension and size of uploaded files
How to use StringBurrer and Arrays.toString.
How to find May'n in XPath
How to use the form_with method
How to use EventBus3 and ThreadMode
How to use the wrapper class
How to use equality and equality (how to use equals)
How to convert LocalDate and Timestamp
How to add the delete function
How to find Java prime numbers
[Rails] How to get the URL of the transition source and redirect
[Swift5] How to get an array and the complement of arrays
How to set the IP address and host name of CentOS8
[Rails] How to introduce kaminari with Slim and change the design
How to install and configure the monitoring tool "Graphite" on Ubuntu
How to install the language used in Ubuntu and how to build the environment
[Java] How to convert from String to Path type and get the path
How to use OrientJS and OrientDB together
How to delete the wrong migration file
[Android] How to turn the Notification panel on and off using StatusBarManager
How to put out the error bundling
[Java] How to use the HashMap class
How to delete the migration file NO FILE
[Java] How to get the current date and time and specify the display format
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
[Java] How to output and write files!
How to determine the number of parallels
How to set up and use kapt
[Java] How to set the Date time to 00:00:00
[Java] How to get the current directory
[Swift] How to implement the countdown function
How to change the timezone on Ubuntu
How to change the maximum and maximum number of POST data in Spark
How to build SquashTM and how to support Japanese
Find the average age from List <Person>.
How to find out the Java version of a compiled class file
Ransack sort_link How to change the color!
[Processing × Java] How to use the class
How to sort the List of SelectItem
How to install the legacy version [Java]
How to pass the value to another screen
How to get the date in java
[Processing × Java] How to use the function
[Java improvement case] How to reach the limit of self-study and beyond
[Easy] How to upgrade Ruby and bundler
[Rails] How to create a table, add a column, and change the column type
How to use substring and substr methods
[Java] How to use the Calendar class