Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有二维数组:
String[][] letters = new String[5][5];
我也有英文字母数组。
String[] alphabet = new String[]{"a", "b", "c", ...};
如何用字母表中的字母填充二维数组? 我期待这样的事情:
{a, b, c, d, e}, {f, g, h, i, j}, {k, l, m, n, o}, {p, q, r, s, t}, {u, v, w, x, y};
试试这个:
for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { letters[i][j] = alphabet[i*5 + j]; } }
当然,"z"不会存储在二维数组中,但你已经知道了。
"z"
你可以用一种简单的方式来做:
String letters[][] = {{"a","b"},{"c","d"}};