-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.java
More file actions
26 lines (23 loc) · 718 Bytes
/
array.java
File metadata and controls
26 lines (23 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;
class array{
public static void main(String args[]){
int[] a1 = {1,2,3,4,5};
System.out.println(a1[1]);
String[] a2 = {"aaa","bbb","ccc"};
System.out.println(a2[0]);
String[] a3 = new String[3];
a3[2]="ccc";
System.out.println(a3[2]);
Scanner abc = new Scanner(System.in);
int val = abc.nextInt();
int[] a4 = new int[val];
int sum=0;
for(int i=0;i<val;i++)
{
a4[i]=abc.nextInt();
sum = sum + a4[i];
}
System.out.println(sum); //sum of elements in an array
System.out.println(a4[(val/2)]); //middle element in an array
}
}