Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

x.Hmfive in a row.. like tictactoe but you need 5 to win.. can someone pls add s

ID: 3617781 • Letter: X

Question

x.Hmfive in a row.. like tictactoe but you need 5 to win.. can someone pls add something that does not allow the players to have the same symbols and if a player chooses a row and column that is not on the board, an error message to indicate it.. thanks!

import java.io.*;
public class untitled
{
    public static void main (String[] args) throws Exception

     {

          BufferedReader keyIn = new BufferedReader(newInputStreamReader(System.in));

          char[][] B = new char[5][5];       // 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<5; i++)
              for(int j=0; j<5; j++)
                  B[i][j] = '-';        
          //display our board
          for (int i=0; i<5; i++)
          {
               for(int j=0; j<5; j++)
                    System.out.print(" " +B[i][j]);
               System.out.println();
           }
          for(int t=0; (t<25) && !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());
                while(B[row][col]!='-')
                      {System.out.println("Invalid move-spot alreadychosen");
                        System.out.println("Player "+(t%players+1));
                  System.out.print("row =");
                  row = Integer.parseInt(keyIn.readLine());
                  System.out.print("column = ");
                   col = Integer.parseInt(keyIn.readLine());
                  }
                       
               B[row][col] = c[t%players];   //alternates betweenplayers
              //display board
               for(int i=0; i<5; i++)
               {
                   for (int j=0;j<5;j++)
                    System.out.print(" " + B[i][j]);
                   System.out.println();
               }
                //check for winner
                //check rows
                for(int i=0;i<players;i++)
                     for(int j=0;j<5;j++)
                         {int k;
                           for( k=0;k<5;k++)
                            {//System.out.println(i+" "+j+" "+k+""+c[i]+" "+B[j][k]);
                               if(c[i]!=B[j][k]) //not that row, go tonext;
                                    k=10;
                                                        &nbs

Explanation / Answer

x.Xlor="red">please rate - thanks import java.io.*; public class untitled {     public static void main (String[] args) throws Exception      {           BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));           char[][] B = new char[5][5];       // 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