Ask Question
11 August, 12:54

Write a method with the signature "float sumArray (float[] data) " that takes an array of floats, and returns their sum.

+2
Answers (1)
  1. 11 August, 15:36
    0
    I will code in JAVA.

    Preconditions:

    The float array of data are declared and initialized.

    public float sumArray (float[] data) {

    float sum = 0;

    for (int i = 0; i < data. length; i++) {

    sum = sum + data[i];

    }

    return sum;

    }

    Explanation:

    First, you have to declare a variable sum of type float and initialize with 0. In addition, this method has a for-loop to go through whole array of data and each element is added to the float value to sum. When the for loop ends, the sum variable is returned.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a method with the signature "float sumArray (float[] data) " that takes an array of floats, and returns their sum. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers