-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtemplate.java
More file actions
44 lines (33 loc) · 962 Bytes
/
Copy pathtemplate.java
File metadata and controls
44 lines (33 loc) · 962 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Java program to demonstrate the
// working of Vector
import java.io.*;
import java.util.*;
import java.util.Collections;
import java.util.Comparator;
class VectorExample {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int n = s.nextInt();
Vector<Integer> v = new Vector<Integer>(n);
for (int i = 1; i <= n; i++)
v.add(s.nextInt());
Comparator comparator = Collections.reverseOrder();
Collections.sort(v,comparator);
// Printing elements
// System.out.println(v);
// // Remove element at index 3
// v.remove(3);
// // Displaying the vector
// // after deletion
// System.out.println(v);
// // Printing elements one by one
// for (int i = 0; i < v.size(); i++)
// System.out.print(v.get(i) + " ");
int ans = 0;
for(int i=2;i<n;i=i+4){
ans+=v.get(i);
}
System.out.println(ans);
}
}