这真的没有意义..如果你想试试这个...
int lottMtch[]=new int[myArray.length];
Arrays.fill(lottMtch, 0);
for (int i = 0; i < 6; i++)
{
int chkNum = myArray[i];
lottMtch[i] = count(chkNum, rndNum);
}
for (int i = 0; i < 6; i++)
{
if (lottMtch[i] > 0)
System.out.println(lottMtch[i] + " matches found "+ myArray[i]);
}
如果你想找到有多少匹配的rndNum
比myArray
试试这个
这里我假设rndNm
是global
int lottMtch=0;
for (int i = 0; i < 6; i++)
{
lottMtch += count(myArray[i], rndNum);
}
if (lottMtch> 0)
System.out.println(lottMtch + " matches found "+ rndNum);
根据评论中的讨论试试这个..
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
for (int i = 0; i < 6; i++)
{
Integer chkNum = myArray[i];
Integer cnt = (Integer)count(myArray[i], rndNum);
if(cnt>0)
{
if(map.get(chkNum)==null)
map.put(chkNum,1);
else
map.put(chkNum, map.get(chkNum)+1);
}
}
for (Object key : map.keySet())
System.out.println(map.get(key) + " matches found "+key.toString());