Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

sum of 1D array(JAVA)

import java.util.Arrays;
import java.util.Scanner;

public class LeetCode_RunningSum {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int[] arr = {1,2,3,4};

        System.out.println(Arrays.toString(out(arr)));

    }

    static int[] out(int[] nums){

        int sum = 0;
        int[] arr = new int[nums.length];

        for (int i = 0; i < nums.length; i++){
            sum += nums[i];
            arr[i] = sum;
        }

        return arr;
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sum
ADD COMMENT
Topic
Name
6+3 =