This program is a game called 5-in-a-row.. it\'s like tictactoe butyou need to g
ID: 3617761 • Letter: T
Question
This program is a game called 5-in-a-row.. it's like tictactoe butyou need to get 5 in order to win.. the problem is that when Itried running it, the board becomes uneven (the 1st column isalways slightly below the other columns; the other columns are allaligned with each other except for the 1st column), and when theuser chooses a column, the program does not even consider the 1stcolumn, example the user chooses the 2nd column, the program startscounting from the 2nd column and makes it appear like the userchose the 3rd column.. in other words, the program also discountsthe 1st column.. I input 0-9 for row and column when asked forthem.. this is the code:import java.io.*;
public class FiveRow {
public static void main (String[] args) throws Exception
{
BufferedReader keyIn = new BufferedReader(newInputStreamReader(System.in));
char[][] B = new char[10][10]; // B is for Board
boolean win = false;
int players;
System.out.print("How many players are there? ");
players = Integer.parseInt(keyIn.readLine());
char[] c = new char[players];
for (int i=0; i<players; i++)
{
System.out.print("enter symbol for player "+(i+1));
c[i]=keyIn.readLine().charAt(0);
}
System.out.println(" ");
System.out.println(" ~~~~~~~~ 5 IN A ROW GAME ~~~~~~~~");
System.out.println(" ");
//initialize our board
for (int i=0; i<10; i++)
for (int j=0; j<10; j++)
B[i][j] = '-';
//display our board
for (int i=0; i<10; i++)
{
for (int j=0; j<10; j++)
System.out.print(" "+ B[i][j]);
System.out.println();
}
for(int t=0; (t<100) && !win ; t++)
{
System.out.println("Player "+(t%players+1));
System.out.print("row = ");
int row = Integer.parseInt(keyIn.readLine());
System.out.print("column = ");
int col = Integer.parseInt(keyIn.readLine());
B[row][col] = c[t%players]; //alternates between players
//display board
for (int i=0; i<10; i++)
{
for (int j=0; j<10; j++)
System.out.print(" "+ B[i][j]);
System.out.println();
}
//check if someone has won already
}
}
}