this program is a game called five in a row.. like tic-tac-toe butyou need 5 to
ID: 3617762 • Letter: T
Question
this program is a game called five in a row.. like tic-tac-toe butyou need 5 to win.. it's a java code.. but it lacks the determinethe winner part.. so can anyone please add it? thanks so muchimport java.io.*;
public class FiveRow {
public static void main (String[] args)throws Exception
{
BufferedReader keyIn = new BufferedReader(newInputStreamReader(System.in));
char[][] B =new char[5][5]; // B is forBoard
boolean win= false;
intplayers;
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(" ");
//initializeour board
for(int i=0;i<5; i++)
for(int j=0; j<5; j++)
B[i][j] = '-';
//displayour board
for (inti=0; i<5; i++)
{
for(int j=0; j<5; j++)
System.out.print(" " +B[i][j]);
System.out.println();
}
for(intt=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());
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();
}
}
}
}
Explanation / Answer
x.Xlor="red">please rate - thanks try this--I only checked it with 1 player 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;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.