@@ -0,0 +1,2445 @@
+import java.util.ArrayList;%0D%0Aimport java.util.Collections;%0D%0A%0D%0A/**%0D%0A *%0D%0A *The MIT License (MIT)%0D%0A *%0D%0A *Copyright (c) 2014 Abhijit Kumar%0D%0A *%0D%0A *Permission is hereby granted, free of charge, to any person obtaining a copy%0D%0A *of this software and associated documentation files (the %22Software%22), to deal%0D%0A *in the Software without restriction, including without limitation the rights%0D%0A *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0D%0A *copies of the Software, and to permit persons to whom the Software is%0D%0A *furnished to do so, subject to the following conditions:%0D%0A *%0D%0A *The above copyright notice and this permission notice shall be included in all%0D%0A *copies or substantial portions of the Software.%0D%0A *%0D%0A *THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0D%0A *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0D%0A *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0D%0A *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0D%0A *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0D%0A *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0D%0A *SOFTWARE.%0D%0A *%0D%0A **/%0D%0A%0D%0A/**%0D%0A * %0D%0A * Given a number N, find the smallest even number E such that E %3E N and digits%0D%0A * in N and E are same. Print NONE otherwise.%0D%0A * %0D%0A * Sample:%0D%0A * %0D%0A * Input%0D%0A * N = 34722641%0D%0A * %0D%0A * Output%0D%0A * E = 34724126%0D%0A * %0D%0A * Input%0D%0A * N = 8234961%0D%0A * %0D%0A * Output%0D%0A * E = 8236194 (instead of 8236149)%0D%0A * %0D%0A * @author abhijitkumar2003%5Bat%5Dgmail%5Bdot%5Dcom%0D%0A * %0D%0A */%0D%0Apublic class NextEvenNumber %7B%0D%0A%09public void nextSmallestEvenNumber(final int number) %7B%0D%0A%09%09boolean found = false;%0D%0A%09%09int nextEven = 0;%0D%0A%09%09String in = String.valueOf(number); // String representation of number%0D%0A%09%09Permutations permute = new Permutations();%0D%0A%09%09ArrayList%3CString%3E anagrams = new ArrayList%3CString%3E();%0D%0A%09%09anagrams = permute.getPermutations(in); // all anagrams of number%0D%0A%09%09Collections.sort(anagrams); // all anagrams of number sorted%0D%0A%09%09for (String str : anagrams) %7B%0D%0A%09%09%09int num = Integer.valueOf(str);%0D%0A%09%09%09if (num %3C number) // discard smaller anagrams%0D%0A%09%09%09%09continue;%0D%0A%09%09%09// first smallest even number %3E input number having same digits as%0D%0A%09%09%09// input number%0D%0A%09%09%09if (num %25 2 == 0) %7B%0D%0A%09%09%09%09found = true;%0D%0A%09%09%09%09nextEven = num;%0D%0A%09%09%09%09break;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09if (found)%0D%0A%09%09%09System.out.println(nextEven);%0D%0A%09%09else%0D%0A%09%09%09System.out.println(%22NONE%22);%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

Given a number N, find the smallest even number E such that E > N and digits in N and E are same.