Skip to content

Instantly share code, notes, and snippets.

@feehe21
Created October 12, 2018 17:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save feehe21/1cb831f97e8c16d052f2c6c8844d8968 to your computer and use it in GitHub Desktop.
import java.util.*;
public class advisorySnacks {
public static void main(String[] args) {
// Creating an ArrayList of String
List<String> students = new ArrayList<>();
// 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 max = students.size();
int min = 0;
int randomNum;
String[] snack = new String[students.size()];
int spot = 0;
while(max > 0){
randomNum = (int)(Math.random() * ((max - min) )) + min;
snack[spot] = students.remove(randomNum);
max --;
spot ++;
}
for(int i = 0; i < snack.length; i++){
System.out.println(snack[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment