Computer Science, asked by tusharshukla1620, 7 hours ago

print the sum of each element in an array​

Answers

Answered by shreebhargavnayak
0

Answer:

print the sum of each element in an array

Answered by pawarsarita696
2

Answer:

public class SumOfArray {

public static void main(String[] args) {

//Initialize array.

int [] arr = new int [] {1, 2, 3, 4, 5};

int sum = 0;

//Loop through the array to calculate sum of elements.

for (int i = 0; i < arr.length; i++) {

sum = sum + arr[i];

Similar questions