forked from FatimaAlazazi/DataStructure2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomRemoves.java
More file actions
31 lines (25 loc) · 949 Bytes
/
RandomRemoves.java
File metadata and controls
31 lines (25 loc) · 949 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
package Task2;
import java.util.Random;
public class RandomRemoves {
static int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
static void RemoveElements(int[] array) {
Random r = new Random();
while (array.length > 0) {
int index = r.nextInt(array.length);
System.out.println("Index = " + index + ", Element = " + array[index]);
int[] array1 = new int[array.length - 1];
for (int i = 0; i < index; i++)
array1[i] = array[i];
for (int i = index; i < array.length - 1; i++)
array1[i] = array[i + 1];
array = array1;
for (int i = 0; i <array.length ; i++) {
System.out.println(array[i]);
}
System.out.println("===============================");
}
}
public static void main(String[] args) {
RemoveElements(a);
}
}