Get item after the array is used up 'n' times
public static void main(String args)
Scanner s=new Scanner(System.in);
System.out.println("Enter the no.of colors");
System.out.println("Enter the array");
String st=new String[n];
System.out.println("Enter the student number");
System.out.println("Student number "+x+" will get
Enter the no.of colors
Enter the array
Enter the student number
Student number 72 will get green
There is in fact only single line of logic to explain. You might however be familiar with java.util.Scanner class and reading values using it. Now, when it comes to the logic, it is very simple. Just divide the student number with the length of the array, the resultant remainder is the position (not index) of the color. As we know that index=position-1 where position of an element in an array represents where it appears. It is just index+1. For instance, red has a position of 1 and index of 0. So first student will pick up red, second student green and so on. Now nth student will pick up n%x positioned element or n%x-1 indexed element.
Carry out the division of 72/5. You will get 2 as remainder and the position of the element is 2 i.e. it's index is 2-1=1.
In this way we can get item after the array after it is reused n times. Feel free to drop a comment.