其他分享
首页 > 其他分享> > Tic-Tac-Toe with AI

Tic-Tac-Toe with AI

作者:互联网

  1. 注意在循环中在try语句中使用nextInt()方法至少两次以上时,如果在第一次nextInt() catch exception 并重新执行循环,那么接下来的nextInt()执行的是之前输入行未读取晚剩下的部分, 有可能进入循环。解决方法是 先全部读取成,然后再判断.
private void nextCell(char[][] cells, Scanner sc) {
        int coX = 0;
        int coY = 0;
        while (true) {
            System.out.println("Enter the coordinates: ");
            try {
                coX = Integer.parseInt(sc.next());
                coY = Integer.parseInt(sc.next());
            } catch (Exception e) {
                System.out.println("You should enter numbers!");
            }
            break;
        }
  1. A类中如果要使用B类中的方法, 可以将B类的实例作为A类的参数,然后在A类中执行B类的方法。

标签:AI,next,nextInt,int,Tac,sc,coY,类中,Toe
来源: https://www.cnblogs.com/longlong6296/p/13917599.html