Checkers board in Java -


as class creating checkers board in eclipse. came code instead of displaying checkers board has 3 white boxes , rest black. here code:

import acm.program.*; import acm.graphics.*; import java.awt.*;  public class checkgame extends graphicsprogram  {     private static final int rows = 8;      private static final int colums = 8;      public void run()     {         int sqsize = getheight() / rows;         (int = 0; i<rows; i++)         {             (int j = 0; j<colums; j++)             {                 int x = j*sqsize;                 int y = i*sqsize;                 grect sq = new grect (x,y,sqsize,sqsize);                 sq.setfilled(((i+j)/2)!=0);                 add(sq);             }         }     } } 

any ideas went wrong? thanks!

instead of

((i+j)/2)!=0 

you want use

((i+j)%2)!=0 

your initial expression 3 times true (0,0 / 0,1 / 1,0), why see 3 white boxes. corrected version depends on whether (i+j)/2 odd or - modulo operator common choice in such cases.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -