简体   繁体   English

2D阵列上的用户输入(Java)

[英]User Input on a 2D Array (Java)

I am trying to implement the knights tour problem on a 3x4 grid display. 我正在尝试在3x4网格显示器上实现骑士巡回问题。 My grid is displayed as follows: 我的网格显示如下:

   A B C D
1: 1 - - -
2: - - - -
3: - - - -

The user starts on A1, which is [0][0] on the 2D array. 用户从A1开始,在2D数组上为[0] [0]。 How would I associate my user input with other positions on the grid. 如何将用户输入与网格上的其他位置相关联。 For example, if the user was to type A2 (I'm aware this isn't a valid knight move) - how would I let the program know this is position [0][1] on the array (I think)? 例如,如果用户键入A2(我知道这不是有效的骑士动作),我如何让程序知道这是数组上的位置[0] [1](我认为)?

Any help would be much appreciated. 任何帮助将非常感激。

假设您有2DArray[i][j]索引i, j :然后可以使用i = rank - 1j = file - 65利用char自动转换为int和ASCII int值来获取正确的2D数组位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM