Find the Number which contain the digit d | Java program to print the number which contain the digit d from 0 to n ; function to display the values ; Converting d to character ; Loop to check each digit one by one . ; initialize the string ; checking for digit ; Driver code
public class GFG { static void printNumbers ( int n , int d ) { String st = " " + d ; char ch = st . charAt ( 0 ) ; for ( int i = 0 ; i <= n ; i ++ ) { st = " " ; st = st + i ; if ( i == d || st . indexOf ( ch ) >= 0 ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 100 , d = 5 ; printNumbers ( n , d ) ; } }