Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Finding the Sum of an Array in Java

    static int arr[] = { 12, 3, 4, 15 };
 
    // method for sum of elements in an array
    static int sum()
    {
        int sum = 0; // initialize sum
        int i;
 
        // Iterate through all elements and add them to sum
        for (i = 0; i < arr.length; i++)
            sum += arr[i];
 
        return sum;
    }
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Finding #Sum #Array #Java
ADD COMMENT
Topic
Name
4+4 =