我在Java中有以下二维数组:
String[][] rows = {
{"M","O","N","K","E","Y"},
{"D","O","N","K","E","Y"},
{"M","A","K","E"},
{"M","U","C","K","Y"},
{"C","O","O","K","Y"},
};
现在我想制作一个列表,其中包含每个字符出现的数组的行数。
所以这一定是结果:
M occurs in 3 rows, O occurs in 3 rows, N occurs in 2 rows, A occurs in 1 row, etc...
(最后一行有两个 O,但在这种情况下,它只需要数一个)
这是我已经采取的步骤:
第 1 步:遍历数组并计算每个字符在整个数组中出现的次数。
第 2 步:遍历数组并查看字符是否已经出现在整个数组中。(布尔值)
这两个步骤对我有所帮助,但我不知道如何比较每个字符的每一行。我想我需要一起检查每个“字符+行组合”并将其与其他所有组合进行比较,但我不知道该怎么做。