我敲了个控制五子棋的界面 但有个小错误硬是找不到啊
public class Gobang{
//定义一个二维数组来冲当棋盘
private String[][] board;
//定义棋盘的大小
private static int BOARD_SIZE = 30;
public void initBoard()
{
//初始化棋盘数组,这里是动态初始化
board = new String[BOARD_SIZE][BOARD_SIZE];
for (int i = 0; i < BOARD_SIZE; i++)
{
for (int j = 0; j < BOARD_SIZE; j++)
{
board[i][j] = "+";
}
}
}
//在控制台输出棋盘的方法
public void printBoard()
{
//打印每个数组元素
for (int i = 0; i < BOARD_SIZE; i ++)
{
for (int j = 0; i < BOARD_SIZE; j ++)
{
//打印数组元素后不换行
System.out.print(board[i][j]);
}
//每打印一行数组就换一行
System.out.print("\n");
}
}
public static void main(String[] args) throws Exception
{
Gobang gb = new Gobang();
gb.initBoard();
gb.printBoard();
//获取键盘输入方法
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputStr = null;
//br.readLine():每当在键盘上输入一行内容后按回车键,刚输入的内容将被br读取到
while ((inputStr = br.readLine()) != null)
{
String[] posStrArr = inputStr.split(",");
int xpos = Integer.parseInt(posStrArr[0]);
int ypos = Integer.parseInt(posStrArr[1]);
//把对应的数组安素赋为“●”
gb.board[ypos - 1][xpos - 1] = "●";
gb.printBoard();
System.out.println("请输入宁下棋的坐标,应以x,y的格式:");
}
}
}