fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.util.stream.Collectors;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. Ideone app = new Ideone() ;
  15. System.out.println(
  16. app.twoIntsAreInRangeAndShareDigits( 20 , 42 )
  17. );
  18. }
  19.  
  20. private boolean twoIntsAreInRangeAndShareDigits ( int n1 , int n2 )
  21. {
  22. String n1String = Integer.toString( n1 );
  23. String n2String = Integer.toString( n2 );
  24. if ( n1String.concat( n2String ).contains( "-" ) ) { return false; } // Return false for negative numbers, being out-of-range 10-99.
  25. if
  26. (
  27. ( n1String.length() == 2 )
  28. &&
  29. ( n2String.length() == 2 )
  30. )
  31. {
  32. Set < Integer > n1CodePoints = n1String.codePoints().boxed().collect( Collectors.toSet() );
  33. Set < Integer > n2CodePoints = n2String.codePoints().boxed().collect( Collectors.toSet() );
  34. n1CodePoints.retainAll( n2CodePoints );
  35. boolean sharesDigit = ( n1CodePoints.size() > 0 );
  36. return sharesDigit;
  37. } else { return false; }
  38. }
  39.  
  40. }
Success #stdin #stdout 0.08s 34396KB
stdin
Standard input is empty
stdout
true