Please bear with me here, I had hospital appointments this week and unfortunately I have NO idea how to use 2D arrays, and barley know arrays for that matter. I am trying to figure them out though. I am running this code below as a test for my project and am getting the following error
How many players? 2
What is your name: alan
What is your name: joseph
Exception in thread "main" 27
alan's Turn!
java.lang.ArrayIndexOutOfBoundsException: 0
at ASgn8.main(ASgn8.java:41)
My code is Below
import java.util.Arrays;
import java.util.Scanner;
class ASgn8 {
public static void main(String[] args)
{
Die[][] myDie = new Die[0][0];
Scanner scan = new Scanner(System.in);
System.out.print("How many players? ");
int playerCount = scan.nextInt();
scan.nextLine();
String[] playerNames = new String[playerCount];
for(int i = 0; i < playerCount; i++)
{
System.out.print("What is your name: ");
playerNames[i] = scan.nextLine();
}
int again = 1;
int randomNum = (int)(Math.random() * (30-10)) +10;
System.out.println(randomNum);
Die firstRoll = new Die();
for(int j = 0; j < 5; j++)
{
System.out.println(playerNames[j] + "'s Turn! ");
firstRoll.roll();
myDie[j][0] = firstRoll;
}
}
}
It highlights the following when i click the error
myDie[j][0] = firstRoll;