public class CheckerBoard
{
public static void main(String[] args)
{
StdDraw.setCanvasSize(600, 600);
for (int i = 0; i < 3; i++)
{
int input = Integer.parseInt(args[i]);
printCheckerboard(input);
}
}
public static void printCheckerboard(int N)
{
StdDraw.setXscale(0, N);
StdDraw.setYscale(0, N);
for (int rows = 0; rows < N; rows++)
{
for (int cols = 0; cols < N; cols++)
{
if((rows + cols) % 2 == 0)
{
StdDraw.setPenColor(StdDraw.RED);
}
else
{
StdDraw.setPenColor(StdDraw.BLACK);
}
StdDraw.filledSquare(cols + .5 , rows + .5, .5);
}
}
StdDraw.show();
}
}
This works fine, but each checkerboard -- different squares/dimensions -- overwrites the other. I want it so that the checkerboards are aligned next to each other in a 1000x1000 canvas size (or something roughly equal). How exactly can should I edit my program?


Sign In
Create Account

Back to top










