ResizeArray, Foreach, While (angefangen...)
parent
4b61367620
commit
361947b09e
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E12_ResizeArray
|
||||
{
|
||||
class Exercise_1
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
int[] arr = [13, 34, 234, 12, 345, 34];
|
||||
|
||||
//Fügen Sie dem oberen Array die Zahl 155 hinzu:
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
|
||||
for(int i = 0; i < arr.Length; i++)
|
||||
Console.Write(arr[i] + " - ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E12_ResizeArray
|
||||
{
|
||||
class Exercise_2
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
Random rand = new();
|
||||
int random = rand.Next(5,20);
|
||||
int[] arr = new int[random];
|
||||
for(int i = 0; i < random; i++)
|
||||
arr[i] = rand.Next(1,1000);
|
||||
|
||||
//Oben wir ein zufälliges Array erstellt. Sorgen Sie dafür, dass den Array eine zufällige Zahl hinzugefügt wird:
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
|
||||
for(int i = 0; i < arr.Length; i++)
|
||||
Console.Write(arr[i] + " - ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E12_ResizeArray
|
||||
{
|
||||
class Exercise_3
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
string[] userinputs = [];
|
||||
//Lassen Sie den User 3 String eingeben. Diese sollen in das obere Array hineingeschrieben werden.
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
}
|
||||
|
||||
Console.Clear();
|
||||
for(int i = 0; i < userinputs.Length; i++)
|
||||
Console.WriteLine(userinputs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace Exercises_C_Sharp.E1_Foreach
|
||||
{
|
||||
class Exercise_1
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
int[] arr = [1, 2, 3, 4];
|
||||
//Geben Sie mit Hilfe einer Foreach-Schleife die Zahlen in dem oberen Array aus:
|
||||
//Code START
|
||||
Console.WriteLine(arr);
|
||||
//Code ENDE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E1_Foreach
|
||||
{
|
||||
class Exercise_2
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
int[] arr = [23, 45, 24, 56, 34, 56, 23, 56, 23, 5];
|
||||
//Addieren Sie alle Werte in dem Array mit einer Foreach-Schleife und geben Sie das Ergebnis aus:
|
||||
//Code START
|
||||
Console.WriteLine(arr);
|
||||
//Code ENDE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E1_Foreach
|
||||
{
|
||||
class Exercise_3
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
int[] arr = [13, 45, 23, 45, 23, 5, 7, 44, 72, 30, 22, 46];
|
||||
//Addieren Sie alle geraden Werte und subtrahieren Sie alle ungeraden Werte in einer Foreach-Schleife. Geben Sie dann das Ergebnis auf der Konsole aus:
|
||||
//Code START
|
||||
Console.WriteLine(arr);
|
||||
//Code ENDE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E1_Foreach
|
||||
{
|
||||
class Exercise_4
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
string[] arr = ["Dies", "ist", "ein", "wunderbarer", "Satz"];
|
||||
//Geben Sie den Satz, dessen Wörter in dem Array oben gespeichert sind, sauber mit Hilfe einer Foreach-Schleife auf der Konsole aus:
|
||||
//Code START
|
||||
Console.WriteLine(arr);
|
||||
//Code ENDE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E1_Foreach
|
||||
{
|
||||
class Exercise_5
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
//Lassen Sie den User einen String eingeben:
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
|
||||
Console.Clear();
|
||||
|
||||
//Geben Sie jeden einzelnen Buchstaben der Eingabedes Users jeweils in einer eigenen Zeile auf der Konsole aus:
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Exercises_C_Sharp.E1_Foreach
|
||||
{
|
||||
class Exercise_6
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
string[] arr = ["Es", "ist", "ein", "wunderschöner", "Morgen"];
|
||||
//Geben Sie jeden einzelnen Buchstaben des Arrays oben auf der Konsole in jeweils einer eigenen Zeile aus:
|
||||
//Code START
|
||||
Console.WriteLine(arr);
|
||||
//Code ENDE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace Exercises_C_Sharp.E14_While
|
||||
{
|
||||
class Exercise_1
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
//Lassen Sie den User einen Integer eingeben:
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
|
||||
//Geben Sie mit Hilfe der While-Schleife alle Wert von der Zahl bis 0 aus:
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Program.cs
25
Program.cs
|
|
@ -219,26 +219,31 @@ namespace Exercises_C_Sharp
|
|||
]
|
||||
};
|
||||
//************************
|
||||
//******Resize Array****** TODO
|
||||
//******Resize Array******
|
||||
//************************
|
||||
ExerciseGroup resizeArrayElements = new()
|
||||
{
|
||||
Name = "12. Resize Array",
|
||||
ElementList = new()
|
||||
{
|
||||
new(){Name = "Übung 1", Method = E18_Methods.Exercise_1.Start}
|
||||
}
|
||||
ElementList = [
|
||||
new(){Name = "Übung 1", Method = E12_ResizeArray.Exercise_1.Start},
|
||||
new(){Name = "Übung 2", Method = E12_ResizeArray.Exercise_2.Start},
|
||||
new(){Name = "Übung 3", Method = E12_ResizeArray.Exercise_3.Start}
|
||||
]
|
||||
};
|
||||
//************************
|
||||
//*******FOREACH******* TODO
|
||||
//*******FOREACH**********
|
||||
//************************
|
||||
ExerciseGroup foreachElements = new()
|
||||
{
|
||||
Name = "13. foreach",
|
||||
ElementList = new()
|
||||
{
|
||||
new(){Name = "Übung 1", Method = E18_Methods.Exercise_1.Start}
|
||||
}
|
||||
ElementList = [
|
||||
new(){Name = "Übung 1", Method = E1_Foreach.Exercise_1.Start},
|
||||
new(){Name = "Übung 2", Method = E1_Foreach.Exercise_2.Start},
|
||||
new(){Name = "Übung 3", Method = E1_Foreach.Exercise_3.Start},
|
||||
new(){Name = "Übung 4", Method = E1_Foreach.Exercise_4.Start},
|
||||
new(){Name = "Übung 5", Method = E1_Foreach.Exercise_5.Start},
|
||||
new(){Name = "Übung 6", Method = E1_Foreach.Exercise_6.Start}
|
||||
]
|
||||
};
|
||||
//************************
|
||||
//**********WHILE********* TODO
|
||||
|
|
|
|||
Loading…
Reference in New Issue