【发布时间】:2022-07-01 19:27:01
【问题描述】:
我希望用户输入一个数字 1-9,并让该数字对应于 3x3 二维数组上的一个位置。然后将该数组中的值更改为“x”。
int input = Convert.ToInt32(Console.ReadLine());
string[,] numbers = {
{ " ", " ", " " },
{ " ", " ", " " },
{ " ", " ", " " }
};
起初我决定这样做:
int x = input % 3 - 1;
int y = input / 3 - 1;
然后在numbers[y, x] 访问数组,但这会导致索引超出范围的问题。
【问题讨论】:
-
是的,当然。只要把数学弄好
-
想想
y为input1 或2 得到的值是什么
标签: c#