Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Week1;
- import java.util.ArrayList;
- import java.util.Random;
- public class RandomNoRepeats
- {
- public static void main(String[] args)
- {
- int size = 10;
- ArrayList<Integer> list = new ArrayList<Integer>(size);
- for(int i = 1; i<=size;i++)
- {
- list.add(i);
- }
- Random rand = new Random();
- while(list.size()>0)
- {
- int index = rand.nextInt(list.size());
- System.out.println("Random #: " + list.remove(index));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement