Print a number containing K digits with digital root D | Java implementation of the above approach ; Function to find a number ; If d is 0 k has to be 1 ; Print k - 1 zeroes ; Driver code
import java . io . * ; class GFG { static void printNumberWithDR ( int k , int d ) { if ( d == 0 && k != 1 ) System . out . print ( " - 1" ) ; else { System . out . print ( d ) ; k -- ; while ( k -- > 0 ) System . out . print ( "0" ) ; } } public static void main ( String [ ] args ) { int k = 4 , d = 4 ; printNumberWithDR ( k , d ) ; } }