Skip to content

Instantly share code, notes, and snippets.

@why404
Created October 28, 2010 14:36
Show Gist options
  • Save why404/651463 to your computer and use it in GitHub Desktop.
Save why404/651463 to your computer and use it in GitHub Desktop.
Write a program that randomly fills in 0s and 1s into an 8 x 8 checker board,prints the board to the dialog box, and reports the rows, columns, and diagonals (more than 2) with all 0s or 1s. Use a two-dimensional array to represent a checker board.
why404@404-ubuntu:~/code$ cat BoardTest.java
// Source Code for BoardTest.java
public class BoardTest
{
public static void main(String args[])
{
char[][] pic = new char[8][8];
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
pic[i][j] = ( i == j || i == 0 || i == 8 ) ? '1' : '0';
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
System.out.print(pic[i][j]);
System.out.println();
}
}
}
why404@404-ubuntu:~/code$ javac BoardTest.java
why404@404-ubuntu:~/code$ java BoardTest
11111111
01000000
00100000
00010000
00001000
00000100
00000010
00000001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment