首页 > 其他 > 详细

Tic-Tac-Toe with AI

时间:2020-11-05 15:12:00      阅读:17      评论:0      收藏:0      [点我收藏+]
  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类的方法。

Tic-Tac-Toe with AI

原文:https://www.cnblogs.com/longlong6296/p/13917599.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!