java五子棋游戏代码,已获万赞

美团一面:

收到了HR的信息,通知我去面试,说实话真的挺紧张的。自己准备了近一个月的时间,很担心面试不过,到时候又后悔不该“裸辞”。

  • 自我介绍
  • spring的IOC,AOP原理
  • springmvc的工作流程
  • handlemapping接收的是什么
  • 项目中你用到了MyBatis,说说#和$的区别
  • MyBatis你写的XML怎么绑定对应的接口?namespace.id
  • Spring有几种方式定义Bean
  • git你用过哪些命令
  • linux怎么在查找目录下的一个文件
  • redis基本数据结构
  • redis单线程模型
  • 事务的四大特性
  • 解释线程池的三个主要参数
  • 具体的问项目中线程池如何使用的(这里因为有些忘记,导致扣了很久)
  • AQS都有什么公共方法
  • 那单例模式和prototype模式,spring都是怎么实现的
  • 计算机网络应用层都有什么协议

美团二面

第二面问的挺多的内容,只记得个大概,所以也只能分享一个我所能记忆到的面试内容

  • 描述从输入一个url到得到结果的过程
  • springMVC的执行过程
  • MVC设计模式
  • static变量初始化在哪个阶段
  • jvm堆中的内存区域分布
  • 垃圾收集算法
  • redis如何实现高并发
  • synchronized是可重入的吗?是公平还是非公平
  • 公平锁和非公平锁的区别、
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Java五子棋游戏代码示例: ``` import java.util.Scanner; public class Gobang { public static final int BOARD_SIZE = 15; public String[][] board = new String[BOARD_SIZE][BOARD_SIZE]; public static final String PLAYER1 = "X"; public static final String PLAYER2 = "O"; public String currentPlayer; public void initBoard() { 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; j < BOARD_SIZE; j++) { System.out.print(board[i][j] + " "); } System.out.println(); } } public boolean isBoardFull() { for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { if (board[i][j].equals("+")) { return false; } } } return true; } public boolean isWinningMove(int row, int col) { String player = board[row][col]; int count = 0; for (int i = 0; i < BOARD_SIZE; i++) { if (board[row][i].equals(player)) { count++; } else { count = 0; } if (count == 5) { return true; } } count = 0; for (int i = 0; i < BOARD_SIZE; i++) { if (board[i][col].equals(player)) { count++; } else { count = 0; } if (count == 5) { return true; } } count = 0; for (int i = -4; i <= 4; i++) { int r = row + i; int c = col + i; if (r >= 0 && r < BOARD_SIZE && c >= 0 && c < BOARD_SIZE) { if (board[r][c].equals(player)) { count++; } else { count = 0; } if (count == 5) { return true; } } } count = 0; for (int i = -4; i <= 4; i++) { int r = row + i; int c = col - i; if (r >= 0 && r < BOARD_SIZE && c >= 0 && c < BOARD_SIZE) { if (board[r][c].equals(player)) { count++; } else { count = 0; } if (count == 5) { return true; } } } return false; } public void play() { initBoard(); currentPlayer = PLAYER1; Scanner scanner = new Scanner(System.in); while (true) { printBoard(); System.out.print("Player " + currentPlayer + ", enter row number: "); int row = scanner.nextInt(); System.out.print("Player " + currentPlayer + ", enter column number: "); int col = scanner.nextInt(); if (board[row][col].equals("+")) { board[row][col] = currentPlayer; if (isWinningMove(row, col)) { printBoard(); System.out.println("Player " + currentPlayer + " wins!"); break; } else if (isBoardFull()) { printBoard(); System.out.println("Game is a tie!"); break; } else { if (currentPlayer.equals(PLAYER1)) { currentPlayer = PLAYER2; } else { currentPlayer = PLAYER1; } } } else { System.out.println("That position is already taken. Try again."); } } } public static void main(String[] args) { Gobang game = new Gobang(); game.play(); } } ``` 这个代码实现了一个交互式的五子棋游戏,玩家可以通过输入行和列号来下棋,程序会检查是否有五子连珠,以及棋盘是否已经下满,如果有则宣布胜者或平局。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值