Find the Number which contain the digit d | Java program to print the number which contain the digit d from 0 to n ; Returns true if d is present as digit in number x . ; Breal loop if d is present as digit ; If loop broke ; function to display the values ; Check all numbers one by one ; checking for digit ; Driver code
class GFG { static boolean isDigitPresent ( int x , int d ) { while ( x > 0 ) { if ( x % 10 == d ) break ; x = x / 10 ; } return ( x > 0 ) ; } static void printNumbers ( int n , int d ) { for ( int i = 0 ; i <= n ; i ++ ) if ( i == d || isDigitPresent ( i , d ) ) System . out . print ( i + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 47 , d = 7 ; printNumbers ( n , d ) ; } }