SUM OF ARRAY

 MAIN.JAVA:

import java.io.*; 
import java.util.*; 
public class Main{ 
    public static void main (String[] args) throws Exception{ 
        int n,sum=0;
        Scanner sc =new Scanner(System.in);
        System.out.println("Enter n :");
        n = sc.nextInt();
        int b[] = new int [n];
        for(int i=0;i<n;i++) {
            b[i] =sc.nextInt();
            sum =sum+ b[i];
        }
        System.out.println("Sum of array elements is : "+sum);

    } 
} 




Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.