2 u012958240 u012958240 于 2013.11.26 09:58 提问

[java] 制作tictactoe 一問
public static void main(String[] args) {
    Scanner input=new Scanner(System.in);
    char [] a ={'0','1','2','3','4','5','6','7','8','9'};
   int choice;
   for (int i=1 ; i<8 ; i++) {
   System.out.println(a[1] + " | " + a[2] + " | " +a[3]);
   System.out.println(a[4] + " | " + a[5] + " | " +a[6]);
   System.out.println(a[7] + " | " + a[8] + " | " +a[9]);
   if (a[i]%2==1) {
   System.out.print("Player X input the position (1-9) :");
   choice=input.nextInt();
   a[choice]= 'X'; }
   else  {
   System.out.print("Player O input the position (1-9) :");
   choice=input.nextInt();
   a[choice]= 'O';  }
   }
   }
}

显示结果为何会输出两个player o
run:
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
Player X input the position (1-9) :3
1 | 2 | X
4 | 5 | 6
7 | 8 | 9
Player O input the position (1-9) :2
1 | O | X
4 | 5 | 6
7 | 8 | 9
Player O input the position (1-9) :

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!