Q:

Java Program to sum the elements of an array

0

Java Program to sum the elements of an array using for loop.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class demo1{
   public static void main(String args[]){
      int[] array = {10, 20, 30, 40, 50, 60};
      int sum = 0;
      //Advanced for loop
      for( int num : array) {
          sum = sum+num;
      }
      System.out.println("Sum of array elements is:"+sum);
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now