Android的 - 计算倍两个数字出现在细胞数 [英] Android - Compute times a two numbers appear in cell number

查看:210
本文介绍了Android的 - 计算倍两个数字出现在细胞数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我。我试图计算特定号码出现在一个表布局行的次数 - 垂直和水平,换句话说。我想补说之间的数字数组(4,5),以让这个数字说,4只出现4次和第5只有两次(垂直&安培;水平)中说6 * 6..take注

Could anyone help me. I am trying to compute the number of times certain numbers appear in a table layout row - vertically and Horizontally, in other words. I would like to fill an array of numbers between say (4 and 5) to make it so that the number say 4 appears only 4times and 5 only twice (vertically & Horizontally) in say 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;  
   }
 }

任何意见将是巨大的,谢谢。

Any advice would be great, thanks.

推荐答案

考虑采取的int数组并在单元格的值的指数增加元素数组中,在最后检查数组中的值。你会得到的时间每个号码出现的次数。

Consider taking an int array and increase the element in the array at index of the value in the cell, at the end check the values in the array. You will get the number of times each number appeared.

例如:结果
号码4已经出现在1,2,第5,6个细胞

Ex:
Number 4 has appeared in 1, 2, 5, 6 cells

array[content of the cell]++;

所以最终阵列[4]给出的4倍的数量出现了。

So at the end array[4] gives the number of times 4 appeared.

这篇关于Android的 - 计算倍两个数字出现在细胞数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆