So I have this code
package role.play.generator;
import java.util.Random;
public class RolePlayGenerator {
public static void main(String[] args) {
Random randomgenerator = new Random();
int hairsel = randomgenerator.nextInt()%5;
String[] haircolours = {"Blue", "Red", "Blonde","Black","Purple"};
double height = Math.floor(Math.random()*9+58);
System.out.println("Height is " + height + " Inches");
System.out.println(haircolours[hairsel]);
}
}
And I keep getting this error
-2 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2 at role.play.generator.RolePlayGenerator.main(RolePlayGenerator.java:11) Java Result: 1
The -2 changes but always stays negative how can I fix this? Every thing else works perfectly.