java program for printing the sum of the elements inn the array

package array_sum;
import java.io.*;
import java.util.Scanner;


    public static void main(String[] args) {
 
        int num,i,sum=0;
        System.out.println("Enter the size of array");
        Scanner sc=new Scanner (System.in);
        num=sc.nextInt();
        int array[]=new int [100];
        System.out.println("Enter the elements in the array one by one");
        for(i=0;i<num;i++)
        {
            array[i]=sc.nextInt();
        }
        System.out.println("The entered element in the array is");
        for(i=0;i<num;i++)
        {
            System.out.println(array[i]);
        }
        System.out.println("The sum of the array is");
        for(i=0;i<num;i++)
        {
            sum=sum+array[i];
        }
        System.out.println(sum);
    }
 
}
OUT-Enter the size of array
5
Enter the elements in the array one by one
89
45
12
45
86
The entered element in the array is
89
45
12
45
86
The sum of the array is
277

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation