Question

    public class MakeQuilt {

public static void main (String[] args){

  char [][] myBlock = new char [4][5];
  char [][] myQuilt = new char [12][4];

  for(int row = 0; row < myBlock.length; row++){
      for(int column = 0; column < myBlock[row].length; column++){
         if(column == 0 || row == 3)
            myBlock[row][column]='X';
         else if(row ==  column || (row == 2 && column == 1))
            myBlock[row][column]='+';
         else
            myBlock[row][column]='.';    
      }   
     }
    displayPattern(myBlock);
    displayPattern(myQuilt);
  }



  public static void displayPattern(char[][] myBlock){

   for(int row = 0; row < myBlock.length; row++){
      for(int column = 0; column < myBlock[row].length; column++){
         System.out.print(myBlock[row][column]);
          }
          System.out.println();
         }
         System.out.println();    
   }

    public static void fillQuilt(char[][] myQuilt){   
   for(int row = 0; row < myQuilt.length; row++){
      for(int column = 0; column < myQuilt[row].length; column++){
         myQuilt[row][column] =('?');
        }
  }
 }
}

Can't seem to figure out why my char array myQuilt won't fill with question marks but instead is filled with nothing? (output shows a bunch of 0's). Not sure how to change the displayPattern method to output ?'s in the myQuilt array.

Was it helpful?

Solution

Before calling displayPattern, you have to fill quilt somewhere. i.e.

displayPattern(myBlock);
fillQuilt(myQuilt);
displayPattern(myQuilt);

OTHER TIPS

Question: You define the fillQuilt(...) method where you would fill an array with question mark characters, but where do you ever call this method?

Answer: You don't (at least you don't show it), and if it's never called, it will never do its thing. The solution is to call the fillQuilt method, passing in myQuilt where you need it to do its actions: fillQuilt(myQuilt);. Understand that programming takes things very literally: they only do what you explicitly program them to do, nothing less, nothing more.

I can't see any call to your fillQuilt() method in your main.

Don't you have to call fillQuilt() somewhere before printing?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top