2017-07-14 19 views
0

私は最初の列にチェッカーボードパターンを取得しています。しかし、私はボード全体を通過し続けることはできません。これは、プログラマーとしての自分のスキルを磨くだけです。私が改善できるものを教えてください! (当該コード)Java:チェッカーボード(8x8)

@Override 
public void start(Stage primaryStage){ 
    //Creates pane 
    AnchorPane pane = new AnchorPane(); 
    Scene scene = new Scene(pane); 
    primaryStage.setScene(scene); 

    int columns = 8, row = 8, horizontal = 125, vertical = 125; 
    Rectangle rectangle = null; 
    for(int i = 0; i < columns; i++){ 
     for(int j = 0; j < row; j++){ 
      //creates the rectangles, and outlines them 
      rectangle = new Rectangle(horizontal*j, vertical*i, horizontal, vertical); 
      rectangle.setStroke(Color.WHITE); 

        if (j+i % 2 == 0) { 
         rectangle.setFill(Color.WHITE); 
        } else { 
         rectangle.setFill(Color.BLACK); 
        }//end else 

      //put rectangles into the pane 
      pane.getChildren().add(rectangle); 
     }//end for-loop j 
    }//end for-loop i 

    //create a scene and place it in the stage 
    scene.setRoot(pane); 
    primaryStage.setTitle("Checkerboard"); 
    primaryStage.show(); 
}//end primaryStage 
+0

あなたの質問は、あなたがデバッグしてみましたか? –

+2

不明ですか – shmosel

+0

EclipseのようなIDEをダウンロードして使用してください。 'setFill'文の前に' System.out.println( "some msg")+ 'を追加して、正しいコードが実行されていることを確認することができます –

答えて

4

%次いで高い優先順位+を有し、第1評価しました。適切な計算を行うには、角カッコを使用します。

if (((j + i) % 2) == 0) {

関連する問題