0

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.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by quuba
0
for (int a = 0; a <= (gridSize * gridSize); a++) {
for (int a = 0; a < (gridSize * gridSize); a++) {
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.