Smallest number whose sum of digits is square of N | Java implementation of the above approach ; Function to return smallest number whose sum of digits is n ^ 2 ; Driver Code
import java . util . * ; class GFG { static int smallestNum ( int n ) { return ( int ) ( ( n * n % 9 + 1 ) * Math . pow ( 10 , n * n / 9 ) - 1 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( smallestNum ( n ) ) ; } }