import java.util.*; /* The game of tic tac toe. The game is represented as a 3x3 grid of characters * which will either be a ' ', 'X', or 'O'. The user will enter the square they * want as two indices, i and j, between 1 and 3. Since Java starts arrays at 0, * we will have to manipulate the user's choice by subtracting 1 from each of i and j. */ public class TicTacToe1 { public static void main(String[] args) { Scanner in=new Scanner(System.in); char[][] grid = new char[3][3]; int i, j; char won = 'n'; boolean legal = true; for(i=0;i<3;i++) for(j=0;j<3;j++) grid[i][j] = ' '; // start off with all grid entries empty do { do { // display the grid // get X's square as 2 integer numbers 0-2, 0-2 (or 1-3,1-3) // check to see if it is a legal move }while(!legal); // check to see if X has won // check to see if the game is a draw do { // display the grid // get O's square as 2 integer numbers 0-2, 0-2 (or 1-3,1-3) // check to see if it is a legal move }while(!legal); // check to see if O has won // check to see if the game is a draw } while(won=='n'); // display the final grid // output who won or if it was a draw } }