The code i am working with is below.
for(int i = 0; i < playerCount; i++)
{
j=0;
System.out.println(playerNames[i] + "'s turn!");
while(userChoice != 2 && j < 5)
{
Die roll2 = new Die();
roll2.roll();
System.out.println(roll2);
diceArray[i][j] = roll2;
System.out.println("Again? 1= yes, 2=no");
userChoice = scan.nextInt();
j++;
}
if(userChoice == 2)
{
userChoice = 1;
}
}
And i am wondering, How could i add a counter, to see how many values are in each row of the array, this is a 2D array, which will have an unknown number of rows, and less than 5 columns. (It could be 5, could be 1.). I cannot do this with a simple count++ because of the multiple rows.
Anyone have any tips?
diceArray.lengthwill return the number ofrowsin the array anddiceArray[0].lengthwill return the number ofcolumns(number of values associated with each row) which i believe is what you are looking for.playerCountfor the rows will save you the negligible amount of time callingdiceArray.lengthwill take.arrayLengthwould then be the value of how manyint[]