2014-04-17 3 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을 보여줍니다). myQuilt 배열에서?를 출력하도록 displayPattern 메서드를 변경하는 방법을 잘 모르겠습니다.내 배열이 '?'로 채워지지 않는 이유는 무엇입니까?

+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()를 호출 할 필요가 없습니까?

관련 문제