import java.util.*; /* The game of tic tac toe. The game is represented as a 9-element array of characters * which will either be a ' ', 'X', or 'O'. The user will enter the square they * want as a number between 1 and 9. Since Java starts arrays at 0, we will have to manipulate * the user's choice by subtracting 1. */ public class TicTacToe1b { public static void main(String[] args) { Scanner in=new Scanner(System.in); char[] board = new char[9]; int i; char won = 'n'; boolean legal = true; for(i=0;i<9;i++) board[i] = ' '; // start off with all grid entries empty do { do { // display the board // get X's square as 1 number 0-8 (or 1-9) // 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 board // get O's square as 1 number 0-8 (or 1-9) // 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 board // output who won or if it was a draw } }