- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumOfArray.java
More file actions
Latest commit
34 lines (24 loc) · 691 Bytes
/
Copy pathSumOfArray.java
File metadata and controls
34 lines (24 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
packageBasics;
importjava.util.Scanner;
/**
* Write a Java program to sum values of an array.
*/
publicclassSumOfArray {
publicstaticvoidmain(String[] args) {
System.out.println("How many Integers ? ");
Scannerscanner = newScanner(System.in);
intnum = scanner.nextInt();
int[] array = newint[num];
for(inti = 0; i < num; i++){
array[i] = scanner.nextInt();
}
sumOfArray(array);
}
privatestaticvoidsumOfArray(int[] array){
intsum = 0;
for (intvalue: array){
sum = sum + value;
}
System.out.print("The sum of the array is " + sum);
}
}