Recursive sum of digits of a number formed by repeated appends | Java program to find Sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; return single digit sum of a number . ; Returns recursive sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; Driver program
class GFG { static int digSum ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } static int repeatedNumberSum ( int n , int x ) { int sum = x * digSum ( n ) ; return digSum ( sum ) ; } public static void main ( String [ ] args ) { int n = 24 , x = 3 ; System . out . println ( repeatedNumberSum ( n , x ) ) ; } }