sum of all numbers in the array using java

The below example shows how to add the all the values of array using core java code

import java.io.DataInputStream;

public class SumOfArrayvalues {

public static void main(String[] args) {
try {
DataInputStream in = new DataInputStream(System.in);
System.out.print(“How many value you want to enter :- “);
int NumberOfValue = Integer.parseInt(in.readLine());

// Input data into array

Integer array[] = new Integer[NumberOfValue];
for (int i = 0; i < NumberOfValue; i++) {
System.out.print(“array[” + i + “]” + ” = “);
array[i] = Integer.parseInt(in.readLine());
}

// Sum all the value logic
int Sum = 0;

for (int i = 0; i < NumberOfValue; i++) {
Sum += array[i];
}
System.out.println(“Sum of all the array values = ” + Sum);
} catch (Exception e) {
System.out.println(e);
}
}
}

output of the above code

How many value you want to enter :- 5
array[0] = 32
array[1] = 34
array[2] = 56
array[3] = 78
array[4] = 29
Sum of all the array values = 229