Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9 | Java implementation to find the sum of all the N digit palindromic numbers divisible by 9 ; Function for finding count of N digits palindrome which are divisible by 9 ; If N is odd ; If N is even ; Function for finding sum of N digits palindrome which are divisible by 9 ; Count the possible number of palindrome ; Driver Code
import java . util . * ; class GFG { static int countPalindrome ( int n ) { int count ; if ( n % 2 == 1 ) { count = ( int ) Math . pow ( 9 , ( n - 1 ) / 2 ) ; } else { count = ( int ) Math . pow ( 9 , ( n - 2 ) / 2 ) ; } return count ; } static int sumPalindrome ( int n ) { int count = countPalindrome ( n ) ; int res = 0 ; if ( n == 1 ) return 9 ; if ( n == 2 ) return 99 ; for ( int i = 0 ; i < n ; i ++ ) { res = res * 10 + count * 5 ; } return res ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( sumPalindrome ( n ) ) ; } }