Ask Question
30 September, 20:52

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

+4
Answers (1)
  1. 30 September, 22:04
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers