FRom hackerrank

Given an array of integers, find the sum of its elements.
For example, if the array , so return .

Solution in java -
import java.util.*;
public class Solution {
    public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int c=0;
     int[] arr = new int[n];
     for(int i=0;i<n;i++) {
         arr[i]= sc.nextInt();
         c=c+arr[i];
     }
     System.out.println(c);
    }
}

Post a Comment

Previous Post Next Post