Advertisement
Vladkoheca

ListStatistics.java

Dec 3rd, 2024 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | Source Code | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner input = new Scanner(System.in);
  8.         int n = input.nextInt();
  9.         int count_of_positives = 0;
  10.         int sum_of_negatives = 0;
  11.  
  12.         ArrayList<Integer> positives = new ArrayList<Integer>();
  13.         ArrayList<Integer> negatives = new ArrayList<Integer>();
  14.  
  15.         for (int i = 0; i < n ; i++){
  16.             int numbers = input.nextInt();
  17.             if(numbers>=0){
  18.                 positives.add(numbers);
  19.                 count_of_positives++;
  20.             } else{
  21.                 negatives.add(numbers);
  22.                 sum_of_negatives+=numbers;
  23.             }
  24.         }
  25.         System.out.println(positives);
  26.         System.out.println(negatives);
  27.  
  28.         System.out.println("Count of positives: " + count_of_positives);
  29.         System.out.println("Sum of negatives: " + sum_of_negatives);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement