Sum of the digits of square of the given number which has only 1 's as its digits | Java implementation of the approach ; Function to return the sum of the digits of num ^ 2 ; To store the number of 1 's ; Find the sum of the digits of num ^ 2 ; Driver code
class GFG { static long squareDigitSum ( String s ) { long lengthN = s . length ( ) ; long result = ( lengthN / 9 ) * 81 + ( long ) Math . pow ( ( lengthN % 9 ) , 2 ) ; return result ; } public static void main ( String [ ] args ) { String s = "1111" ; System . out . println ( squareDigitSum ( s ) ) ; } }