944,081 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 362
  • Java RSS
Oct 9th, 2009
0

Method problems

Expand Post »
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.
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster
KimJack is offline Offline
114 posts
since Apr 2006
Oct 9th, 2009
0
Re: Method problems
Java Syntax (Toggle Plain Text)
  1. for (int a = 0; a <= (gridSize * gridSize); a++) {
  2. for (int a = 0; a < (gridSize * gridSize); a++) {
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Inheritance and Polymorphism
Next Thread in Java Forum Timeline: Please Help! Can someone tell me what this error means and how to fix it?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC