Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could implement this using a <code>Hashtable</code>. Using your code as a base, I've written an example implementation but without knowing what it is you are trying to do, I can't judge if this is what you are looking for. </p> <pre><code>import java.util.Hashtable; public class findPat { static final int COUNT = 100; static Hashtable&lt;String, Integer&gt; compareSet = new Hashtable&lt;String, Integer&gt;(); static String groupInteger = ""; static int arr [] = new int [5]; static int st = 1; static int end = 56; static double t1; static double t2; public static void main(String[] args) { t1=System.currentTimeMillis(); for(int n = 0; n &lt; COUNT; n++){ for (int i = 0; i &lt; arr.length; i++) { arr[i] = (int) (Math.random()* (end - st + 1)) + st; } for (int i = 1; i &lt;= 5; i++) { groupInteger += arr[i-1]; System.out.print("\t" + arr[i-1]); if (i % 5 == 0) { System.out.println(); if (compareSet.containsKey(groupInteger)) { System.out.println("duplicate found"); int currentCount = compareSet.get(groupInteger); compareSet.put(groupInteger, currentCount + 1); } else { compareSet.put(groupInteger, 1); } groupInteger = ""; } } } t2=System.currentTimeMillis(); System.out.println(); System.out.println(); System.out.println("\t" + "Total run time is " + ((t2 - t1)) + "ms"); } } </code></pre> <p>This code keeps track of the unique sets of random numbers by adding them (creating a key value that is the same for every set that has the same values in the same order, the concatenated string takes care of this). </p> <p>Your code ran in 13 seconds on my system, mine takes 17 seconds. Now if runtime is of crucial importance, you might want to look into hashing techniques. But I'm not sure if you will be able to shave off a lot as you will have to add some extra code which will take extra time. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload