FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 191   



Java program that loop over an array of numbers and calculate the sum of all those numbers

public class ArrayElementsSum {

    public static void main(String[] args) {

          int[] array = {10, 20, 30, 40, 50, 20};
          int result = 0;

          for( int i : array) {
              result += i;
          }

          System.out.println("Sum of all elements is:" + result);    
    }
}

Output:

Sum of all elements is:170



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News