任何人都可以帮助我。我试图计算某些数字在表格布局行中出现的次数 - 换句话说,垂直和水平。我想在说(4和5)之间填充一组数字,以使数字说4只出现4次而5只出现两次(垂直和水平),比如说6 * 6..take note
我如何使用其中任何一项?
public boolean hasRepeatedNumbers(int[] x) {
int[] y = new int[x.length];
System.arraycopy(x, 0, y, 0, y.length);
Array.sort(y);
int i;
for (i = 1; i < y.length; i++) {
if (y[i] == y[i-1]) return true;
}
return false;
}
或
private int[] calculateUsedCells(int x, int y) {
int c[] = new int[2];
// horizontal
for (int i = 0; i < 2; i++) {
if (i == y)
continue;
int t = getCell(x, i);
if (t != 0)
c[t - 1] = t;
}
}
任何建议都会很棒,谢谢。
答案 0 :(得分:0)
考虑使用int数组并在单元格中的值的索引处增加数组中的元素,最后检查数组中的值。您将获得每个号码出现的次数。
例如:
4号出现在1,2,5,6个细胞中
array[content of the cell]++;
所以在结束时[4]给出4次出现的次数。