Skip to content

Instantly share code, notes, and snippets.

@husnain-iqbal
Created February 15, 2016 14:40
Show Gist options
  • Save husnain-iqbal/02e2f5c2f96f28ff2ef2 to your computer and use it in GitHub Desktop.
Save husnain-iqbal/02e2f5c2f96f28ff2ef2 to your computer and use it in GitHub Desktop.
You are given an array of integers of size NN. Can you find the sum of the elements in the array? Input The first line of input consists of an integer NN. The next line contains NN space-separated integers representing the array elements. Sample: 66 11 22 33 44 1010 1111 Output Output a single value equal to the sum of the elements in the array.…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int arr[] = new int[n];
int sum = 0 ;
for(int arr_i=0; arr_i < n; arr_i++){
arr[arr_i] = in.nextInt();
sum += arr[arr_i];
}
System.out.println(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment