File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ write a program that creates integer array of n elements, accepts the values of arrays and find sum of elements as an integer.
3
+
4
+ Input Format
5
+
6
+ Accepts n values from the user.
7
+
8
+ Constraints
9
+
10
+ All number should be integer values (Positive, negative and zero)
11
+
12
+ Output Format
13
+
14
+ diplays the sum of the array's elements as a single integer.
15
+
16
+ Sample Input 0
17
+
18
+ 5
19
+ 3 4 10 11 20
20
+ Sample Output 0
21
+
22
+ 48
23
+ */
24
+ import java .io .*;
25
+ import java .util .*;
26
+
27
+ public class Solution {
28
+
29
+ public static void main (String [] args ) {
30
+ /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
31
+ Scanner sc = new Scanner (System .in );
32
+ int n = sc .nextInt ();
33
+ if (n >0 )
34
+ {
35
+ int []arr = new int [n ];
36
+ for (int i =0 ;i <n ;i ++)
37
+ arr [i ] = sc .nextInt ();
38
+ int sum = 0 ;
39
+ for (int i : arr )
40
+ sum += i ;
41
+ System .out .print (sum );
42
+ }
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments