fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.stream.*;
  4. import java.util.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Test
  10. {
  11. public static void main (String[] args) throws java.lang.Exception {
  12. List<Integer> list = findNumbers(new int[]{22,123,456,145,5,3,000,10,453});
  13. list.forEach(data -> System.out.println(data));
  14. }
  15. private static List<Integer> findNumbers(int[] is) {
  16. return Arrays.stream(is).filter(Test::is123).sorted().boxed().collect(Collectors.toList());
  17. }
  18. private static boolean is123(int x) {
  19. if (x == 0) return false;
  20. while (x != 0) {
  21. if (x%10 < 1 || x%10 > 3) return false;
  22. x /= 10;
  23. }
  24. return true;
  25. }
  26.  
  27. }
Success #stdin #stdout 0.25s 34088KB
stdin
Standard input is empty
stdout
3
22
123