-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathclear_vector.java
More file actions
26 lines (26 loc) · 872 Bytes
/
clear_vector.java
File metadata and controls
26 lines (26 loc) · 872 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.Scanner;
import java.util.Vector;
public class Example {
public static void main(String[] args) {
//1
Vector vector = new Vector<>();
int size;
Scanner sc = new Scanner(System.in);
//2
System.out.println("Enter the size of the vector : ");
size = sc.nextInt();
//3
for (int i = 0; i < size; i++) {
System.out.println("Enter value for position " + (i + 1) + " : ");
vector.add(sc.nextInt());
}
//4
System.out.println("You have entered : " + vector);
System.out.println("Size of the vector is : " + vector.size());
//5
vector.clear();
//6
System.out.println("After the vector is cleared : " + vector);
System.out.println("Size of the vector after cleared : " + vector.size());
}
}