Advertisement
vvsvvs

Untitled

May 16th, 2022
534
139 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp2
  6. {
  7.     class positiv_negativ_count_with_Linq
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> list = new List<int>(Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
  12.  
  13.             List<int> positive = list.Where(num => num >= 0).ToList();
  14.             List<int> negative = list.Where(num => num < 0).ToList();
  15.  
  16.             Console.WriteLine($"Count positiv:{positive.Count}");
  17.             Console.WriteLine($"Count negativ:{negative.Count}");
  18.             Console.WriteLine($"Sum positiv:{positive.Sum()}");
  19.             Console.WriteLine($"Sum negative:{negative.Sum()}");
  20.         }
  21.     }
  22. }
  23.  
Advertisement
RAW Paste Data Copied
Advertisement