/* * TicTacToe.java * * Author: RageOfOrder * * Created on February 19, 2007, 8:00 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; String leftPad = " ", rightPad = ""; // Create the left and right space pads for( int i = 1; i < (cellSize / 2); i++ ) { leftPad += " "; rightPad += " "; } // Adjust for possible if( cellSize % 2 > 0 ) rightPad += " "; // Set up the format of the cell: [Left pad, character, right pad] format = "[%1$s%2$s%3$s]"; for( int i = 0; i < marks.length; i++ ) { if( i % 3 == 0 && i != 0) System.out.println(); System.out.format( format, leftPad, marks[ i ], rightPad ); } System.out.println(); } public static void main(String[] args) { char marks[] = { ' ', 'X', 'O', 'X', 'O', ' ', 'X', ' ', 'O' }; dspBoard(9, marks ); } }