E20 Ex1-7

This commit is contained in:
Sebastian Schüler 2025-09-23 16:18:52 +02:00
parent a0aba34283
commit e5ecb8149e
7 changed files with 37 additions and 16 deletions

View File

@ -13,7 +13,7 @@ namespace Exercises_C_Sharp.E20_Lists
for(int i = 0; i < 10; i++)
{
/*Code START*/
intList.Add(i + 1);
/*Code ENDE*/
}

View File

@ -11,7 +11,8 @@ namespace Exercises_C_Sharp.E20_Lists
//Erstellen Sie eine Liste, in die unten die drei Werte reingeschrieben werden:
/*Code START*/
dynamic superList = 1;
//List<string> superList = new();
List<string> superList = [];
/*Code ENDE*/
superList.Add("Hallo");

View File

@ -13,15 +13,22 @@ namespace Exercises_C_Sharp.E20_Lists
List<string> stringList = new List<string>();
stringList.Add(", wie");
stringList.Add("'s?");
/*Code START*/
stringList.Insert(0, "Hallo");
stringList.Insert(2, " geht");
//oder:
stringList = ["Hallo, wie geht's?"];
/*Code ENDE*/
//Kontrolle:
foreach(var element in stringList)
foreach (var element in stringList)
Console.Write(element);
}
}

View File

@ -9,17 +9,18 @@ namespace Exercises_C_Sharp.E20_Lists
public static void Start()
{
//Geben Sie das Doppelte der ersten Zahl, das Dreifache der zweiten Zahl, das Vierfache der dritten Zahl usw. aus der Liste aus:
List<int> intList = new List<int>() {14,2,12,32,51,31,53,12,34,34,2,45,45,23,62,72,25,40};
List<int> intList = new List<int>() { 14, 2, 12, 32, 51, 31, 53, 12, 34, 34, 2, 45, 45, 23, 62, 72, 25, 40 };
/*Code START*/
for (int i = 0; i < intList.Count; i++)
Console.WriteLine(intList[i] * (i+2));
/*Code ENDE*/
//Kontrolle:
//28 - 6 - 48 - 160 usw....
//Kontrolle:
//28 - 6 - 48 - 160 usw....
}
}
}

View File

@ -11,9 +11,11 @@ namespace Exercises_C_Sharp.E20_Lists
//Geben Sie die folgenden Informationen über die Zahlen in der Liste aus: Größte Zahl, kleinste Zahl, Durchschnitt (arithmetisches Mittel):
List<int> intList = new List<int>() {14,2,12,32,51,31,53,12,34,34,2,45,45,23,62,72,25,40};
/*Code START*/
/*Code START*/
Console.WriteLine("Größte Zahl: " + intList.Max());
Console.WriteLine("Kleinste Zahl: " + intList.Min());
Console.WriteLine("Durchschnitt: " + intList.Average());
/*Code ENDE*/
}

View File

@ -11,9 +11,10 @@ namespace Exercises_C_Sharp.E20_Lists
//Geben Sie den Medianwert der folgenden Zahlenreihe an. Der Medianwert ist der Wert, der bei einer sortierten Reihe genau in der Mitte steht:
List<int> intList = new List<int>() {14,2,12,32,51,31,53,12,34,34,2,45,45,23,62,72,25,40};
/*Code START*/
Console.WriteLine("Medianwert: " + intList[intList.Count / 2]); //ToDo: Absichern
/*Code ENDE*/
}

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection.Metadata.Ecma335;
namespace Exercises_C_Sharp.E20_Lists
{
@ -24,15 +25,23 @@ namespace Exercises_C_Sharp.E20_Lists
static List<int> RemoveOdds(List<int> intList)
{
/*Code START*/
return intList;
List<int> tempList = [];
foreach (var element in intList)
if (element % 2 == 0)
tempList.Add(element);
return tempList;
/*Code ENDE*/
}
static List<int> RemoveOdds2(List<int> intList) => intList.Where(k => k % 2 == 0).ToList();
static List<int> RemoveEvens(List<int> intList)
{
/*Code START*/
return intList;
List<int> tempList = [];
foreach (var element in intList)
if (element % 2 == 1)
tempList.Add(element);
return tempList;
/*Code ENDE*/
}
}