Answer:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String numSales;
ArrayList<Integer> average = new ArrayList<>();
while ((numSales = in.readLine()) != null) {
int number = Integer.parseInt(numSales);
average.add(number);
}
OptionalDouble avg = average.stream().mapToDouble(a -> a).average();
System.out.println(avg);
}
}
Step-by-step explanation:
Just convert the input to an array, and then find the average after looping for all of the values in the input.
From the sample input of:
3
4
8
My output gives:
5.0