elena1234

Read Jagged Array from the Console

Dec 17th, 2020 (edited)
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.  
  5. namespace JaggedArray
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int rows = int.Parse(Console.ReadLine());
  12.             int[][] jaggedArray = new int[rows][];
  13.             for (int row = 0; row < rows; row++)
  14.             {
  15.                 int[] currentRow = Console.ReadLine().Split().Select(int.Parse).ToArray();
  16.                 jaggedArray[row] = currentRow;
  17.             }
  18.  
  19.             foreach (int[] currentRow in jaggedArray) // to print the Array
  20.             {
  21.                 Console.WriteLine(string.Join(" ",currentRow));
  22.             }
  23.         }
  24.     }
  25. }
  26.  
Add Comment
Please, Sign In to add comment