Ask Question

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

+4
Answers (1)
  1. 12 June, 15:52
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers