Uebungsaufgaben_ITFS2_SS_2025/Exercises/E27_Jagged_Arrays/Exercise_4.cs
2025-10-06 15:28:54 +02:00

49 lines
1.5 KiB
C#

using System;
using System.IO;
using System.Collections.Generic;
namespace Exercises_C_Sharp.E27_Jagged_Arrays
{
class Exercise_4
{
static int[][] JaggedArray = new int[][]
{
new int[] {1234, 2712, 993843, 273273, 382783},
new int[] {93847, 3827362, 3049384, 384738, 2938273},
new int[] {3948374, 39485, 3029384, 30493847, 30293849, 2738203},
new int[] {949302, 495874, 483747, 392910, 3049381, 3723901, 39409381, 3784803, 2838499},
new int[] {3892, 29302, 392830, 9583,573483, 38492, 1923, 39403}
};
public static void Start()
{
//Sorgen Sie dafür, dass im Jagged Array oben alle ungeraden Zahlen herausgelöscht werden. Geben Sie dann das Array zur kontrolle aus.
//Code START
int[][] tempArr = new int[JaggedArray.Length][];
for (int i = 0; i < JaggedArray.Length; i++)
{
List<int> tempList = [];
foreach (var element in JaggedArray[i])
if (element % 2 == 0)
tempList.Add(element);
tempArr[i] = tempList.ToArray();
}
JaggedArray = tempArr;
foreach (var arr in JaggedArray)
{
foreach (var element in arr)
{
Console.Write(element + " ");
}
Console.WriteLine();
}
//Code ENDE
}
}
}