tampurus

19 Sum of array elements

Apr 25th, 2022 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. // Q19 Sum array elements
  2. import java.util.*;
  3. public class Main
  4. {
  5.     public static void main(String[] args) {
  6.         int[] arr ={1,2,3,4,5};
  7.         int sum = 0;
  8.         System.out.println("Sum of array elements is ");
  9.         for(int n : arr){
  10.             sum+=n;
  11.         }
  12.         System.out.print(sum);
  13.     }
  14. }
  15. /*
  16. Enter the number
  17. Sum of array elements is
  18. 15
  19. */
Add Comment
Please, Sign In to add comment