Created
October 16, 2018 14:24
-
-
Save landjd19/aa0a768692c67f355ff85259f851fe23 to your computer and use it in GitHub Desktop.
RandomOrder ArrayList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Write a description of class RandomOrder here. | |
* | |
* @author (jake landaiche) | |
* @version (a version number or a date) | |
*/ | |
import java.util.*; | |
public class RandomOrder | |
{ | |
public static void main(String[] args){ | |
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 total = students.size(); | |
String [] snackOrder = new String[total]; | |
int max = total - 1; | |
for(int i = 0; i < total; i++){ | |
int min = 0; | |
int randomNum = (int)(Math.random() * ((max - min) )) + min; | |
snackOrder[i] = students.get(randomNum); | |
students.remove(randomNum); | |
max--; | |
System.out.println(snackOrder[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment