@@ -26,14 +26,14 @@ 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...
3635
36+ numbers [ 2 ] = 68 ;
3737
3838
3939 // ... AND THIS LINE
@@ -43,14 +43,13 @@ public int[] one()
4343
4444 public String two ( )
4545 {
46- throw new NotImplementedException ( ) ;
4746 String [ ] teachers = { "Nathan" , "Ed" , "Dave" , "Carlo" , "Lewis" , "Jules" , "John" , "Chris" , "Nigel" } ;
4847
4948 //TODO: 2. Using an array index, change the value of the teacher variable below to be the fourth
5049 // teacher contained in the teachers array
5150 // WRITE YOUR CODE BETWEEN THIS LINE...
5251
53- String teacher = "" ;
52+ String teacher = teachers [ 3 ] ;
5453
5554 // ... AND THIS LINE
5655
@@ -59,39 +58,38 @@ public String two()
5958
6059 public String [ ] three ( )
6160 {
62- throw new NotImplementedException ( ) ;
6361 //TODO: 3. Create a string array named cars that contains three names of car manufacturers: Audi, BMW and Dodge
6462 // WRITE YOUR CODE BETWEEN THIS LINE...
65-
66-
63+ String [ ] cars = { "Audi" , "BMW" , "Dodge" } ;
6764
6865 // ... AND THIS LINE
6966
70- // return cars;
67+ return cars ;
7168 }
7269
7370 public int four ( )
7471 {
75- throw new NotImplementedException ( ) ;
7672 int [ ] numbers = { 42 , 13 , 17 , 91 } ;
7773
7874 // TODO 4. Using array indices, set the value of the result variable below to the sum of every number in the numbers array
7975 // WRITE YOUR CODE BETWEEN THIS LINE...
8076
8177 int result = 0 ;
82-
78+ foreach ( int element in numbers )
79+ {
80+ result += element ;
81+ }
8382 // ... AND THIS LINE
8483
8584 return result ;
8685 }
8786
8887 public float [ ] five ( )
8988 {
90- throw new NotImplementedException ( ) ;
9189 //TODO: 5. Create an array called floats that contains 3 floating point numbers: 9.62, 23.17 and 3.14
9290 // WRITE YOUR CODE BETWEEN THIS LINE...
9391
94- float [ ] floats ;
92+ float [ ] floats = { 9.62f , 23.17f , 3.14f } ;
9593
9694
9795 // ... AND THIS LINE
0 commit comments