Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws Exception {
- List<Double> integerList = getIntegerList();
- System.out.println("min="+getMinimum(integerList));
- System.out.println("max="+getMaximum(integerList));
- System.out.println("sum="+getSum(integerList));
- System.out.println("avg="+String.format("%.2f",getAvg(integerList)));
- }
- public static double getMinimum(List<Double> array){
- return Collections.min(array);
- }
- public static double getMaximum(List<Double> array){
- return Collections.max(array);
- }
- public static double getSum(List<Double> array){
- return array.stream().mapToInt(Double::intValue).sum();
- }
- public static double getAvg(List<Double> array){
- double sum = 0;
- if (!array.isEmpty()){
- for (Double arr : array){
- sum+=arr;
- }
- return sum/array.size();
- }
- return sum;
- }
- public static List<Double> getIntegerList() throws IOException{
- Scanner scanner = new Scanner(System.in);
- double N = scanner.nextDouble();
- List<Double> newList = new ArrayList<>();
- for (int i=0; i<N; i++){
- newList.add(scanner.nextDouble());
- }
- return newList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment