五子棋怎么在棋盘顶上标数字?
就是下面这样的``左边的行数字可以随行对称`可是`最顶上面那排列数字```怎么排都不对称`...`
 0 1 2 3 4 5
0++++++++++++
1++++++++++++
2++++++++++++
3++++++++++++
4++++++++++++下面是我的代码`有点乱``package item.gobang;
import java.util.*;public class Gobang2
{

public static void main(String[] args) 
{
Scanner input=new Scanner(System.in);
//阶段1 分析业务;创建字符串类型二维数组,使用”╋”初始化棋盘数组
 String  [][]board=new String[15][15];
for(int i=0;i<15;i++)
{
for(int j=0;j<15;j++)
{
board[i][j]="╋";
}
}


//阶段2 定义并初始化所需的变量,打印欢迎界面.
boolean onoff=true;
boolean huamian=true;
String per;  //定义落子方
int count=0; //定义换人下子的计数器循环白黑用
int count2=0 ;//计合棋用

System.out.println("\t\t欢乐五子棋");
System.out.println("*************************************");
System.out.println("玩法:输入X-Y左边如:1-2");

//阶段3 
//开始游戏对战
//编程输出棋盘,并提示该由哪方落子,(输入落子的坐标字符串)

while(onoff==true)
{
//输出棋盘
for(int i=0;i<15;i++) 
{
if(i<10)                  //打印前面数字
{
System.out.print("0"+i);
}else
{
System.out.print(i);
}

for(int j=0;j<15;j++)       //打印格子
{
System.out.print(board[i][j]);
}
System.out.println();
}

if(huamian==false)  //如果huamian=false时表示要跳出循环了`后面的要用
{
break;
}
//提示该由哪方落子
if(count%2==0)  //如果为偶数`定义per的值
{
per="白";
}else
{
per="黑";
}

System.out.print("由("+per+")方落子(输入q退出):");
String zi=input.next(); 
if(zi.equals("q"))
{
System.out.println("谢谢使用");
break;
}
String []point=zi.split("-");   //把输入数字截断

//1.坐标的有效性,只能是数字,不能超出棋盘范围
boolean isnum=Character.isDigit(point[0].charAt(0));
if(isnum==false)
{
System.out.println("输入数字错误`请从新输入");
continue;
}

int row=Integer.parseInt(point[0]); //得到左边的数
int col=Integer.parseInt(point[1]); //得到右边的数

//如果输入的数字大于14则从新输入;
if(row>14||col>14)
{
System.out.println("不好意思`输入的坐标只能是14以内:请从新输入");
continue;
}


//2.如果下棋的点已经有棋了,则不能重复下棋
if(board[row][col]!="╋")   //不等于+时`表示已经有棋
{
System.out.println("此处已下子,不能重复下棋");
continue;
}
if(per.equals("白"))
{
board[row][col]="○";
}else
{
board[row][col]="●";//●
}
count++;  //如果下子成功`换人的计数器+1

//3.每次下棋后,需要扫描谁赢了


int count3=1; //计数器`计算相等棋子数量
     //横向扫描
for(int i=0;i<15;i++)
{
if(col==14)
{
break;
}

 if(board[row][col].equals(board[row][col+1]))
{
count3++;
col++;


}
}
 row=Integer.parseInt(point[0]);  //还原左右边数字
     col=Integer.parseInt(point[1]);
for(int i=0;i<15;i++)
{
if(col==0)
{
break;
}
if(col>0&&board[row][col].equals(board[row][col-1]))
{
 count3++;
 col--;
}

}
if(count3>4)
 {
 System.out.println(per+"方落子赢了");
 huamian=false; //已经赢了`要跳出循环`并显示最后画面
 }
 row=Integer.parseInt(point[0]); //还原左右边数字
     col=Integer.parseInt(point[1]);

//竖向扫描
count3=1;  //计数清0
for(int i=0;i<15;i++)
{

 if(row<14&&board[row][col].equals(board[row+1][col]))
{
count3++;
row++;

}else
{
break;
}
 
}

row=Integer.parseInt(point[0]); //还原左右边数字
     col=Integer.parseInt(point[1]);

for(int i=0;i<15;i++)
{

if(row>0&&board[row][col].equals(board[row][row-1]))
{
 count3++;
 row--;
}

}
if(count3>4)
 {
 System.out.println(per+"方落子赢了");
 huamian=false; //已经赢了`要跳出循环`并显示最后画面
 }
row=Integer.parseInt(point[0]); //还原左右边数字
     col=Integer.parseInt(point[1]);


//左斜方向扫描
count3=1;  //计数清0
for(int i=0;i<15;i++)
{
 if((col<14&&row<14)&&board[row][col].equals(board[row+1][col+1]))
{
count3++;
row++;
col++;

}else
{
break;
}
}
row=Integer.parseInt(point[0]); //还原左右边数字
    col=Integer.parseInt(point[1]);
    
for(int i=0;i<15;i++)
{
if((col>0&&row>0)&&board[row][col].equals(board[row-1][col-1]))
{
 count3++;
 row--;
 col--;
}else
{
break;
}
}
if(count3>4)
 {
 System.out.println(per+"方落子赢了");
 huamian=false; //已经赢了`要跳出循环`并显示最后画面
 }
row=Integer.parseInt(point[0]); //还原左右边数字
    col=Integer.parseInt(point[1]);


//右斜方向扫描
count3=1;  //计数清0
for(int i=0;i<15;i++)
{
 if((row<14&&col>0)&&board[row][col].equals(board[row+1][col-1]))
{
count3++;
row++;
col--;

}else
{
break;
}
}

row=Integer.parseInt(point[0]); //还原左右边数字
    col=Integer.parseInt(point[1]);
for(int i=0;i<15;i++)
{
if((row>0&&col<14)&&board[row][col].equals(board[row-1][col+1]))
{
 count3++;
 row--;
 col++;
}else
{
break;
}
}
if(count3>4)
 {
 System.out.println(per+"方落子赢了");
 huamian=false; //已经赢了`要跳出循环`并显示最后画面
 }
row=Integer.parseInt(point[0]); //还原左右边数字
    col=Integer.parseInt(point[1]);

//扫描是否和棋
for(int i=0;i<15;i++)
{
for(int j=0;j<15;j++)
{
if(board[i][j]=="╋")
{
count2++;   //计算空位的数量
}
}
}
if(count2==0)    //如果空位等于0时候`棋盘已满
{
System.out.println("合棋了````````");
}
count2=0;          //计算空位的变量清0 

System.out.println("");


}

//阶段4 
//产生落子坐标以后,涉及以下几点:
//1.坐标的有效性,只能是数字,不能超出棋盘范围
//2.如果下棋的点已经有棋了,则不能重复下棋。
//3.每次下棋后,需要扫描谁赢了,并扫描是否和棋(棋盘占满了)   }}

解决方案 »

  1.   

    你把DOS窗的输出的字体改成等宽就对上了.
    这种程序还是做成GUI比较方便.
      

  2.   

    没办法呀``刚上JAVA课`才学到数组`还没学到那里去``
    明天要交作业郁闷的很`
      

  3.   

    public class Test { /**
     * @param args
     */
    public static void printState(char[][] state){
    System.out.print("  ");
    for(int i=0;i<state[0].length;i++){
    System.out.print((char)('a'+i)+" ");
    }
    System.out.println();
    for(int i=0;i<state.length;i++){
    System.out.print((char)('a'+i)+" ");
    for(int j=0;j<state[i].length;j++){
    System.out.print(state[i][j]+" ");
    }
    System.out.println();
    }
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    char[][] state=new char[8][8];
    for(int i=0;i<state.length;i++){
    for(int j=0;j<state[i].length;j++){
    state[i][j]='+';
    }
    }
    printState(state);
    }}
    测试结果:
      a b c d e f g h 
    a + + + + + + + + 
    b + + + + + + + + 
    c + + + + + + + + 
    d + + + + + + + + 
    e + + + + + + + + 
    f + + + + + + + + 
    g + + + + + + + + 
    h + + + + + + + + 
    用字母表示吧,数字的话2位数就不好控制了
      

  4.   

    如果输入1-a `这时候输入进去的是"1-a"怎么把后面的a变成0呢?
    String zi=input.next(); 
    String []point=zi.split("-");  //把输入数字截断 
    int row=Integer.parseInt(point[0]); //得到左边的数 
    int col=Integer.parseInt(point[1]);  //这句?
    最后一句该怎么改呀???
      

  5.   

    int col=Integer.parseInt(point[1].charAt(0)-'a');
    试一下吧
      

  6.   

    错了,直接
    int col=point[1].charAt(0)-'a';
      

  7.   

    charAt(0)-'a'
    这个方法是什么意思呀``麻烦解释一下`
    是不是把a转换成0?
    如果变1是不是charAt(1)-'a'?`
    可是我那条语句不是固定发呀?
    int col=Integer.parseInt(point[1]);
    point[1]的值随着输入改变?
      

  8.   


    point[1].charAt(0)-'a';
    LZ看一下API吧,charAt()是String类的常用方法
    point[1]是一个String类型
    point[1].charAt(0)是取point[1]的第一个字符......
    ‘a'-'a'得到整形数值