title: Sorting an array of int in lexicographic order
body: <p>I came across a problem such that:</p>
  
  <blockquote>
    <p>WAP to sort prime numbers smaller than given N by digits. If N is 40,
    the output should be 11, 13, 17, 19, 2, 23, 29, 3, 31, 37, 39, 5, 7.
    Note: Limit memory use.</p>
  </blockquote>
  
  <p>Getting primary number was the easy. But I could not figure out an efficient way of lexicographic sorting of array of integer.</p>
  
  <pre><code>public static void getPrimeNumbers(int limit) {
          for (int i=2; i&lt;=limit; i++) {
              if(isPrime(i)) {
                  System.out.println(i);
              }
          }
      }
  
      public static boolean isPrime(int number) {
          for(int j=2; j&lt;number; j++) {
              if(number%j==0) {
                  return false;
              }
          }
              return true;
      }
  
      public static void lexographicSorting() {
          int[] input = {2,3,5,7,11,13,17,19};
          int[] output = {};
          for (int i=0; i&lt;input.length; i++) {
              for(int j=0; j&lt;input.length; j++) {
                  ////Stuck at this part.
              }
          }
      }
  </code></pre>