java - How to print statement outside loop to avoid duplicates? -


i print statement outside loop statement doesn't print same thing on , over. loop below checks number 1 array against find out how many matches have been found. defining variables above , printing statements below results in "variable not initialised error" understandable.

for (int = 0; < 6; i++) {     int chknum = myarray[i];     int lottmtch = count(chknum, rndnum);      if (lottmtch > 0)     {         system.out.println(lottmtch + "matches found");         system.out.print(chknum);     }     else {         system.out.print("no matches found");     } } 

this not make sense .. if want try ...

        int lottmtch[]=new int[myarray.length];            arrays.fill(lottmtch, 0);             (int = 0; < 6; i++)             {                 int chknum = myarray[i];                lottmtch[i] = count(chknum, rndnum);              }             (int = 0; < 6; i++)             {                        if (lottmtch[i] > 0)                               system.out.println(lottmtch[i] + " matches found "+ myarray[i]);             } 

if wan found how many match of rndnum in myarray try

here assume rndnm global

        int lottmtch=0;              (int = 0; < 6; i++)             {                 lottmtch += count(myarray[i], rndnum);              }                         if (lottmtch> 0)                               system.out.println(lottmtch + " matches found "+ rndnum); 

as per discussed in comment try ..

map<integer,integer> map = new hashmap<integer,integer>();          (int = 0; < 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);               }           }           (object key : map.keyset())               system.out.println(map.get(key) + " matches found "+key.tostring()); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -