Method problems

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2006
Posts: 114
Reputation: KimJack is an unknown quantity at this point 
Solved Threads: 0
KimJack KimJack is offline Offline
Junior Poster

Method problems

 
0
  #1
Oct 9th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz
 
0
  #2
Oct 9th, 2009
  1. for (int a = 0; a <= (gridSize * gridSize); a++) {
  2. for (int a = 0; a < (gridSize * gridSize); a++) {
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC