title: Given a number N, find the smallest even number E such that E > N
body: <p>Given a number N, find the smallest even number E such that E > N and digits in N and E are same.</p>
  
  <pre><code>   Print NONE otherwise.
      Sample:
  Case1
      Input
      N = 34722641 
      Output
      E = 34724126
  Case2
      Input
      N = 8234961
      Output
      E = 8236194 (instead of 8236149)
  </code></pre>
  
  <p>My second case passed first case i am getting wrong output</p>
  
  <pre><code>public static int nextDigit(int number) {
  String num = String.valueOf(number);
  int stop = 0;
  char[] orig_chars = null;
  char[] part1 = null;
  char[] part2 = null;
  orig_chars = num.toCharArray();
  
  for (int i = orig_chars.length - 1; i &gt; 0; i--) {
      String previous = orig_chars[i - 1] + "";
      String next = orig_chars[i] + "";
      if (Integer.parseInt(previous) &lt; Integer.parseInt(next))
  {
      if (Integer.parseInt(previous) % 2 == 0) {
  
          String partString1 = "";
          String partString2 = "";
          for (int j = 0; j &lt;= i - 1; j++) {
              partString1 = partString1.concat(orig_chars[j] + "");
          }
          part1 = partString1.toCharArray();
          for (int k = i; k &lt; orig_chars.length; k++) {
              partString2 = partString2.concat(orig_chars[k] + "");
          }
          part2 = partString2.toCharArray();
          Arrays.sort(part2);
          for (int l = 0; l &lt; part2.length; l++) {
              char temp = '0';
              if (part2[l] &gt; part1[i - 1]) {
                  temp = part1[i - 1];
                  part1[i - 1] = part2[l];
                  part2[l] = temp;
                  break;
              }
          }
          for (int m = 0; m &lt; part2.length; m++) {
              char replace = '0';
              if (part2[m] % 2 == 0) {
                  replace = part2[m];
                  for (int n = m; n &lt; part2.length - 1; n++) {
                      part2[n] = part2[n + 1];
                  }
                  part2[part2.length - 1] = replace;
                  break;
              }
          }
  
          System.out.print(part1);
          System.out.println(part2);
          System.exit(0);
          }
      }
  }
       System.out.println("NONE");
  
    return 0;
      }
  </code></pre>