Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * Write a description of class Snacks here.
- *
- * @Drew (your name)
- * @1 (a version number or a date)
- */
- public class Snacks
- {
- // instance variables - replace the example below with your own
- /**
- * Constructor for objects of class Snacks
- */
- public Snacks()
- {
- // Creating an ArrayList of String
- ArrayList<String> students = new ArrayList<String>();
- int max;
- int min;
- int randomNum;
- // Adding new elements to the ArrayList
- students.add("Sameer");
- students.add("Praneeth");
- students.add("Robert");
- students.add("Nishant");
- students.add("Michael");
- students.add("PeterL");
- students.add("Evan");
- students.add("William");
- students.add("Raunaq");
- students.add("Rahul");
- students.add("Neil");
- students.add("PeterD");
- students.add("Jonathan");
- int listLength = students.size();
- String[] list = new String[listLength];
- for(int i = 0; i < listLength; i++){
- max = students.size();
- min = 0;
- randomNum = (int)(Math.random() * ((max - min) )) + min; //exclusive
- list[i] = students.get(randomNum);
- students.remove(randomNum);
- }
- for(int f = 0; f < list.length; f++){
- System.out.println(list[f]);
- }
- }
- }
Add Comment
Please, Sign In to add comment