From e0f75d39ef0b0e02b53c439fecf40371a94fce7f Mon Sep 17 00:00:00 2001 From: Nikolaos Litsas Date: Wed, 10 Jan 2024 15:33:44 +0200 Subject: [PATCH] Core --- .../java/com/booleanuk/core/Exercise.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index f4aec33..ecd74ef 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -22,7 +22,7 @@ public int[] one() { // 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... - + numbers[2] = 68; // ... AND THIS LINE @@ -37,7 +37,7 @@ public String two() { // teacher contained in the teachers array // WRITE YOUR CODE BETWEEN THIS LINE... - String teacher = ""; + String teacher = teachers[3]; // ... AND THIS LINE @@ -47,14 +47,13 @@ public String two() { public String[] three() { // 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 // Then change the code below to remove the dummyArray completely and return the cars array you created above instead. - String[] dummyArray = {}; - return dummyArray; + return cars; } public int four() { @@ -63,8 +62,11 @@ public int four() { // 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 number : numbers) { + result = result + number; + } + // ... AND THIS LINE @@ -74,13 +76,13 @@ public int four() { public float[] five() { // 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 = {9.62f, 23.17f, 3.14f}; // ... AND THIS LINE // Then change the code below to remove the dummyArray completely and return the floats array you created instead - float[] dummyArray = {}; - return dummyArray; + + return floats; } }