2014-04-17 287 views
2
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] =('?'); 
     } 
    } 
} 
} 

似乎无法弄清楚为什么我的char数组myquilt不会填满问号,而是什么都不填充? (输出显示一串0)。不知道如何改变displayPattern方法在myQuilt数组中输出?。为什么我的数组不填充'?'?

+0

它没有填满问号,因为没有填充问号。 – immibis

回答

3

在致电displayPattern之前,您必须在某处填充被子。即

displayPattern(myBlock); 
fillQuilt(myQuilt); 
displayPattern(myQuilt); 
+0

doh!现在就开始工作了。谢谢! – user3543798

+0

欢迎您... – iMBMT

1

问题:您可以定义fillQuilt(...)方法,您可以在其中填充带有问号字符的数组,但您从哪里调用此方法?

答:你不(至少你不显示它),如果它从来没有被调用,它将永远不会做它的事情。解决方法是调用fillQuilt方法,在需要执行其操作的地方传入myQuilt:fillQuilt(myQuilt);。理解编程需要的东西非常字面:他们只做你明确规划他们做的事情,没有什么更多的。

0

我看不到你的mainfillQuilt()方法的调用。

0

在打印之前,您是否需要在某处调用fillQuilt()?

相关问题