/* * TicTacToe.java * * Author: RageOfOrder * * Created on February 19, 2007, 11:28 PM * * Comments: Craige is a silly rhinocerous */import java.io.*;public class TicTacToe{ public static void dspBoard( int size, char[] marks ) { int cellSize = size/3; int fullSize = size + 2; String format, blankFormat, dashLine = ""; String leftPad = " ", rightPad = ""; // Create the left and right space pads for( int i = 1; i < (cellSize / 2); i++ ) { leftPad += " "; rightPad += " "; } // Create the line of -'s for( int i = 0; i < size + 2; i++ ) dashLine += "-"; // Adjust for possible if( cellSize % 2 > 0 ) rightPad += " "; // Set up the format of the line format = "%4$s%1$s%5$s|%4$s%2$s%5$s|%4$s%3$s%5$s\n"; // Set up a blank line format blankFormat = "%1$s %2$s|%1$s %2$s|%1$s %2$s\n"; for( int i = 0; i < 9; i += 3 ) { for( int j = 0; j < Math.floor( cellSize/2 ); j++ ) System.out.format( blankFormat, leftPad, rightPad ); System.out.format( format, marks[ i ], marks[ i+1 ], marks[ i+2 ], leftPad, rightPad ); for( int j = 0; j < Math.ceil( cellSize/2 ); j++ ) System.out.format( blankFormat, leftPad, rightPad ); if( i < 6 ) System.out.println( dashLine ); } System.out.println(); } public static void main(String[] args) { char marks[] = { ' ', ' ', ' ', ' ', 'X', ' ', ' ', ' ', ' ' }; dspBoard(9, marks ); }}