954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Method problems

For some reason this method prints out an extra integer at the bottom. For example: It is supposed to only print out 4 x4.

20 20 20 20
20 20 20 20
20 20 20 20
20 20 20 20
20

Any idea how to remove the extra character?

public void gridOfChars(int gridSize) {
for (int i = 0; i < 2; i++) {
for (char n = 'A'; n <= 'Z'; n++)
{
gameList.add(n);
}
}
shuffle(gameList);
copyGameList = gameList.subList(0, (gridSize * 2));
temp = new ArrayList<Character>(copyGameList);
temp2 = new ArrayList<Character>(temp);
temp.addAll(temp2);
shuffle(temp);
gameList = temp;


//displays grid of chars for text display
int newLine = 0;
for (int a = 0; a <= (gridSize * gridSize); a++) {
newLine++;
System.out.print(" " + gameList.get(a));

if (newLine == gridSize)
{
System.out.println();
newLine = 0;
}
}
}

Any assistance will be great thanks, Kimjack.

KimJack
Junior Poster
114 posts since Apr 2006
Reputation Points: 8
Solved Threads: 0
 
for (int a = 0; a <= (gridSize * gridSize); a++) {
for (int a = 0; a < (gridSize * gridSize); a++) {
quuba
Posting Pro
573 posts since Nov 2008
Reputation Points: 123
Solved Threads: 106
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You