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

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat