E20 Ex 1 - 5
This commit is contained in:
parent
1fcd56b9f5
commit
b9b90b23a9
@ -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*/
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ 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(); oder = new List<string>();
|
||||
/*Code ENDE*/
|
||||
|
||||
superList.Add("Hallo");
|
||||
|
@ -15,7 +15,11 @@ namespace Exercises_C_Sharp.E20_Lists
|
||||
stringList.Add("'s?");
|
||||
|
||||
/*Code START*/
|
||||
stringList.Insert(0, "Hallo");
|
||||
stringList.Insert(2, " geht");
|
||||
|
||||
//ODER:
|
||||
stringList = ["Hallo, wie geht's?"]; //= new() {"Hallo, wie geht's?"};
|
||||
|
||||
/*Code ENDE*/
|
||||
|
||||
|
@ -13,7 +13,8 @@ namespace Exercises_C_Sharp.E20_Lists
|
||||
|
||||
|
||||
/*Code START*/
|
||||
|
||||
for(int i = 0; i<intList.Count; i++)
|
||||
Console.Write(intList[i] * (i + 2) + " - ");
|
||||
|
||||
/*Code ENDE*/
|
||||
|
||||
|
@ -14,6 +14,26 @@ namespace Exercises_C_Sharp.E20_Lists
|
||||
|
||||
/*Code START*/
|
||||
|
||||
Console.WriteLine("Größte Zahl: " + intList.Max());
|
||||
Console.WriteLine("Kleinste Zahl: " + intList.Min());
|
||||
Console.WriteLine("Durchschnitt: " + intList.Average());
|
||||
|
||||
//ODER:
|
||||
int min = int.MaxValue;
|
||||
int max = int.MinValue;
|
||||
int sum = 0;
|
||||
int amount = 0;
|
||||
foreach(var element in intList)
|
||||
{
|
||||
if(element < min) min = element;
|
||||
if(element > max) max = element;
|
||||
sum += element;
|
||||
amount++;
|
||||
}
|
||||
Console.WriteLine("Größte Zahl: " + max);
|
||||
Console.WriteLine("Kleinste Zahl: " + min);
|
||||
Console.WriteLine("Durchschnitt: " + ((double)sum / amount));
|
||||
|
||||
|
||||
/*Code ENDE*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user