This is the first solution to find the sum of integers in an array, using the core logic.
public class SumOfArrayElements {
public static void main(String[] args) {
//Initialize the array with integer values
int [] arrNums=new int[] {54,72,19,180,46,11};
int sumNums=0;
//Iterate the array of integers
for(int i=0;i<arrNums.length;i++) {
sumNums += arrNums[i];
}
System.out.println("The sum of integers in an array="+sumNums);
}
}
The sum of integers in an array=382

Leave a comment