TheBulgarianWolf

Removing Negative Nums And Printing In Reverse

Nov 10th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SoftUniLists
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Console.Write("Enter your numbers here: ");
  12.             List<int> numbers = ReadList();
  13.             foreach(int number in numbers)
  14.             {
  15.                 if(number < 0)
  16.                 {
  17.                     numbers.Remove(number);
  18.                 }
  19.             }
  20.  
  21.             if(numbers.Count == 0)
  22.             {
  23.                 Console.WriteLine("Empty");
  24.             }
  25.             else
  26.             {
  27.                 for(int i = numbers.Count - 1; i >= 0; i--)
  28.                 {
  29.                     Console.Write(numbers[i] + " ");
  30.                 }
  31.             }
  32.  
  33.  
  34.         }
  35.  
  36.         static List<int> ReadList(int n)
  37.         {
  38.             var list = new List<int>();
  39.             for (int i = 0; i < n; i++)
  40.             {
  41.                 list.Add(int.Parse(Console.ReadLine()));
  42.             }
  43.  
  44.             return list;
  45.         }
  46.  
  47.         static List<int> ReadList()
  48.         {
  49.             List<int> list = new List<int>();
  50.             var line = Console.ReadLine();
  51.             list = line.Split().Select(int.Parse).ToList();
  52.             return list;
  53.         }
  54.  
  55.        
  56.  
  57.         static void PrintList(List<int> list)
  58.         {
  59.             for (int i = 0; i < list.Count; i++)
  60.             {
  61.                 Console.WriteLine(list[i]);
  62.             }
  63.         }
  64.     }
  65. }
  66.  
Add Comment
Please, Sign In to add comment