- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumOfTwo.java
More file actions
Latest commit
19 lines (19 loc) · 541 Bytes
/
Copy pathSumOfTwo.java
File metadata and controls
19 lines (19 loc) · 541 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
importjava.util.Scanner;
classSumOfTwo{
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
inti,n,sum=0;
System.out.println("Enter the number of element:");
n = sc.nextInt();
inta [] = newint[n];
System.out.println("Enter the element");
for(i = 0; i< n ; i++){
a[i] = sc.nextInt();
}
for(i=0; i<n; i++)
{
sum += a[i];
}
System.out.println("Sum of "+n+" elements in an array = "+sum);
}
}