Skip to content

Commit f59cb62

Browse files
all tests passed
1 parent 337b13b commit f59cb62

File tree

1 file changed

+19
-9
lines changed
  • csharp-fundamentals-arrays.Main

1 file changed

+19
-9
lines changed

csharp-fundamentals-arrays.Main/Core.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ public void example()
2626

2727
public int[] one()
2828
{
29-
throw new NotImplementedException();
3029
int[] numbers = { 42, 13, 17, 91 };
3130

3231
// 1. Values contained in an array are each stored at a unique numeric index, starting from 0 ascending in order.
3332
// E.g. The first value is at index 0, the second at index 1, the third at index 3.
3433
// Using an index, change the number 17 in the numbers array to 68
3534
// WRITE YOUR CODE BETWEEN THIS LINE...
36-
35+
for (int i = 0; i < numbers.Length; i++)
36+
{
37+
if (numbers[i] == 17)
38+
{
39+
numbers[i] = 68;
40+
break;
41+
}
42+
}
3743

3844

3945
// ... AND THIS LINE
@@ -43,14 +49,17 @@ public int[] one()
4349

4450
public String two()
4551
{
46-
throw new NotImplementedException();
4752
String[] teachers = { "Nathan", "Ed", "Dave", "Carlo", "Lewis", "Jules", "John", "Chris", "Nigel" };
4853

4954
//TODO: 2. Using an array index, change the value of the teacher variable below to be the fourth
5055
// teacher contained in the teachers array
5156
// WRITE YOUR CODE BETWEEN THIS LINE...
5257

5358
String teacher = "";
59+
for (int i = 0; i < teachers.Length; i++)
60+
{
61+
teacher = teachers[3]; // Index 3 corresponds to the fourth element
62+
}
5463

5564
// ... AND THIS LINE
5665

@@ -59,26 +68,28 @@ public String two()
5968

6069
public String[] three()
6170
{
62-
throw new NotImplementedException();
6371
//TODO: 3. Create a string array named cars that contains three names of car manufacturers: Audi, BMW and Dodge
6472
// WRITE YOUR CODE BETWEEN THIS LINE...
65-
73+
String[] cars = {"Audi", "BMW", "Dodge"};
6674

6775

6876
// ... AND THIS LINE
6977

70-
//return cars;
78+
return cars;
7179
}
7280

7381
public int four()
7482
{
75-
throw new NotImplementedException();
7683
int[] numbers = { 42, 13, 17, 91 };
7784

7885
// TODO 4. Using array indices, set the value of the result variable below to the sum of every number in the numbers array
7986
// WRITE YOUR CODE BETWEEN THIS LINE...
8087

8188
int result = 0;
89+
for (int i = 0; i < numbers.Length; i++)
90+
{
91+
result += numbers[i]; // Add each number to the result
92+
}
8293

8394
// ... AND THIS LINE
8495

@@ -87,11 +98,10 @@ public int four()
8798

8899
public float[] five()
89100
{
90-
throw new NotImplementedException();
91101
//TODO: 5. Create an array called floats that contains 3 floating point numbers: 9.62, 23.17 and 3.14
92102
// WRITE YOUR CODE BETWEEN THIS LINE...
93103

94-
float[] floats;
104+
float[] floats = { 9.62f, 23.17f, 3.14f };
95105

96106

97107
// ... AND THIS LINE

0 commit comments

Comments
 (0)