Hey everyone!
So, I'm making a hangman game. I'm at the very beginning stages so I just have a String array and just to make sure it works correctly I want to print a random word from the array - simple, right? I am running into an error - the output is below. I would be so happy if you guys could help!!!
here is the code - and yes Hangman2 is the correct name.

import java.util.*;

public class Hangman2 {
    public static void main(String [] args){
        Random random  = new Random();
        int rgen = random.nextInt(10)+1;
        System.out.println(rgen); //print random to test
        String [] wordList = new String [10];
        wordList[1] = "table";
        wordList[2] = "shed";
        wordList[3] = "computer";
        wordList[4] = "because";
        wordList[5] = "knight";
        wordList[6] = "table";
        wordList[7] = "hover";
        wordList[8] = "hat";
        wordList[9] = "racecar";
        wordList[10] = "scissors";
        System.out.println(wordList[rgen]);

    }
}

This is the output:

1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
    at Hangman2.main(Hangman2.java:23)

please!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.