MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / ArraySum

Class ArraySum

Java/Array/ArraySum.java:36–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34import java.util.Scanner;
35
36public class ArraySum {
37
38 public static int arraySum(int[] arr) {
39 int n = arr.length;
40 int sum = 0;
41 for (int i = 0; i < n; i++) {
42 sum = sum + arr[i];
43 }
44 return sum;
45 }
46
47 public static int[] takingInput() {
48 Scanner sc = new Scanner(System.in);
49 int n = sc.nextInt();
50 int[] arr = new int[n];
51 for (int i = 0; i < n; i++) {
52 arr[i] = sc.nextInt();
53 }
54 return arr;
55 }
56
57 public static void main(String[] args) {
58 int[] arr = takingInput();
59 int n = arraySum(arr);
60 System.out.println(n);
61 }
62}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected