From f59cb62e6317c7758a49231dfc45cda478ee2ef8 Mon Sep 17 00:00:00 2001 From: Mathias Handeland <127216029+MathiasHandeland@users.noreply.github.com> Date: Fri, 8 Aug 2025 15:15:45 +0200 Subject: [PATCH] all tests passed --- csharp-fundamentals-arrays.Main/Core.cs | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/csharp-fundamentals-arrays.Main/Core.cs b/csharp-fundamentals-arrays.Main/Core.cs index 74d7769..ad16168 100644 --- a/csharp-fundamentals-arrays.Main/Core.cs +++ b/csharp-fundamentals-arrays.Main/Core.cs @@ -26,14 +26,20 @@ public void example() public int[] one() { - throw new NotImplementedException(); int[] numbers = { 42, 13, 17, 91 }; // 1. Values contained in an array are each stored at a unique numeric index, starting from 0 ascending in order. // E.g. The first value is at index 0, the second at index 1, the third at index 3. // Using an index, change the number 17 in the numbers array to 68 // WRITE YOUR CODE BETWEEN THIS LINE... - + for (int i = 0; i < numbers.Length; i++) + { + if (numbers[i] == 17) + { + numbers[i] = 68; + break; + } + } // ... AND THIS LINE @@ -43,7 +49,6 @@ public int[] one() public String two() { - throw new NotImplementedException(); String[] teachers = { "Nathan", "Ed", "Dave", "Carlo", "Lewis", "Jules", "John", "Chris", "Nigel" }; //TODO: 2. Using an array index, change the value of the teacher variable below to be the fourth @@ -51,6 +56,10 @@ public String two() // WRITE YOUR CODE BETWEEN THIS LINE... String teacher = ""; + for (int i = 0; i < teachers.Length; i++) + { + teacher = teachers[3]; // Index 3 corresponds to the fourth element + } // ... AND THIS LINE @@ -59,26 +68,28 @@ public String two() public String[] three() { - throw new NotImplementedException(); //TODO: 3. Create a string array named cars that contains three names of car manufacturers: Audi, BMW and Dodge // WRITE YOUR CODE BETWEEN THIS LINE... - + String[] cars = {"Audi", "BMW", "Dodge"}; // ... AND THIS LINE - //return cars; + return cars; } public int four() { - throw new NotImplementedException(); int[] numbers = { 42, 13, 17, 91 }; // TODO 4. Using array indices, set the value of the result variable below to the sum of every number in the numbers array // WRITE YOUR CODE BETWEEN THIS LINE... int result = 0; + for (int i = 0; i < numbers.Length; i++) + { + result += numbers[i]; // Add each number to the result + } // ... AND THIS LINE @@ -87,11 +98,10 @@ public int four() public float[] five() { - throw new NotImplementedException(); //TODO: 5. Create an array called floats that contains 3 floating point numbers: 9.62, 23.17 and 3.14 // WRITE YOUR CODE BETWEEN THIS LINE... - float[] floats; + float[] floats = { 9.62f, 23.17f, 3.14f }; // ... AND THIS LINE