- Joined
- Jun 14, 2021
- Messages
- 6
- Reaction score
- 0
I would like to learn how to randomly remove the elements from an array in Java, one at a time. The below program is what I have written:
I am looking for help with printing the result to check that it is empty (might need toString) and also the logic for removing the elements.
Java:
//randomly remove elements from an array
import java.util.Random;
public class Main {
public static void main(String[] args) {
int size = 5;
Random r = new Random();
int result = r.nextInt(size);
String[] arr1 = {"1", "2", "3", "4", "5", "6"};
for (int i = 0; i < size; i++) {
arr1[i] = arr1[size];
}
System.out.println(arr1);
}
}
I am looking for help with printing the result to check that it is empty (might need toString) and also the logic for removing the elements.