![]() |
To calculate the average of two lists in Java we first need to combine the two lists into one. we can do this using the addAll() method of the ArrayList class. Once you have combined the lists we can calculate the average by summing up all the elements in the combined list and dividing by the total number of factors. Methods to Find Average of Two ListsThere are three methods to find the average of the two lists are mentioned below:
1. Using simple for loop +len() and + OperatorBelow is the Implementation of the above method: Java
Output
Average: 3.5 2. Using the sum(), len(), and + operatorsBelow is the Implementation of the above method: Java
Output
Average: 3.5 3. Using sum() + len() + chain()Below is the Implementation of the above method: Java
Output
Average: 5.5 |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 9 |