Numbers having Unique ( or Distinct ) digits | Java code for the above approach ; Function to print unique numbers ; Iterate from l to r ; Convert the no . to String ; Convert String to set using stl ; Output if condition satisfies ; Driver Code ; Input of the lower and higher limits ; Function Call
import java . util . * ; class GFG { static void printUnique ( int l , int r ) { for ( int i = l ; i <= r ; i ++ ) { String s = String . valueOf ( i ) ; HashSet < Integer > uniDigits = new HashSet < Integer > ( ) ; for ( int c : s . toCharArray ( ) ) uniDigits . add ( c ) ; if ( s . length ( ) == uniDigits . size ( ) ) { System . out . print ( i + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int l = 1 , r = 20 ; printUnique ( l , r ) ; } }