Computer Applications

Write a code segment to compute the sum of all positive real numbers stored in the following array.

double numb[] = new double[50];

Java Arrays

18 Likes

Answer

double sum = 0;
for (int i = 0; i < 50; i++) {
    if (numb[i] > 0) {
        sum += numb[i];
    }
}
System.out.println("Sum of positive real numbers = " + sum);

Answered By

14 Likes


Related Questions