-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.java
More file actions
30 lines (28 loc) · 760 Bytes
/
Copy pathdemo.java
File metadata and controls
30 lines (28 loc) · 760 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
27
28
29
30
class demo{
public static void display(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i] +" ");
}
}
public static void main(String[] args) {
int[] arr = {1,2,3,4,5};
int left=0, right=arr.length-1;
display(arr);
while(left < right){
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
System.out.println("\n");
display(arr);
int sum=0;
for(int i =0;i<arr.length;i++){
if(i%2==0){
sum = sum+arr[i];
}
}
System.out.println("\nsum "+ sum);
}
}