Advertisement
Guest User

Array List

a guest
Apr 28th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. package Week1;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. public class RandomNoRepeats
  7. {
  8.  
  9. public static void main(String[] args)
  10. {
  11. int size = 10;
  12. ArrayList<Integer> list = new ArrayList<Integer>(size);
  13.  
  14. for(int i = 1; i<=size;i++)
  15. {
  16. list.add(i);
  17. }
  18.  
  19. Random rand = new Random();
  20. while(list.size()>0)
  21. {
  22. int index = rand.nextInt(list.size());
  23. System.out.println("Random #: " + list.remove(index));
  24.  
  25. }
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement