import java.io.*;
public class SumOfElementsInArray
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Total Number of Elements:: ");
int n = Integer.parseInt(br.readLine());
int[] a = new int[n];
int i, sum = 0;
// Read elements from user
for (i = 0; i < a.length; i++)
{
System.out.print("Enter Element:: ");
a[i] = Integer.parseInt(br.readLine());
}
//Perform Addition
for (i = 0; i < a.length; i++)
{
sum = sum + a[i];
}
System.out.print("Sum of Elements present in Array is:: " + sum);
}
}
public class SumOfElementsInArray
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Total Number of Elements:: ");
int n = Integer.parseInt(br.readLine());
int[] a = new int[n];
int i, sum = 0;
// Read elements from user
for (i = 0; i < a.length; i++)
{
System.out.print("Enter Element:: ");
a[i] = Integer.parseInt(br.readLine());
}
//Perform Addition
for (i = 0; i < a.length; i++)
{
sum = sum + a[i];
}
System.out.print("Sum of Elements present in Array is:: " + sum);
}
}
OUTPUT::
Enter Total Number of Elements:: 4
Enter Element:: 2
Enter Element:: 5
Enter Element:: 9
Enter Element:: 1
Sum of Elements present in Array is:: 17