Smallest and Largest Palindrome with N Digits | Java implementation of the above approach ; Function to print the smallest and largest palindrome with N digits ; Driver Code
class GfG { static void printPalindrome ( int n ) { if ( n == 1 ) { System . out . println ( " Smallest ▁ Palindrome : ▁ 0" ) ; System . out . println ( " Largest ▁ Palindrome : ▁ 9" ) ; } else { System . out . println ( " Smallest ▁ Palindrome : ▁ " + ( int ) ( Math . pow ( 10 , n - 1 ) ) + 1 ) ; System . out . println ( " Largest ▁ Palindrome : ▁ " + ( ( int ) ( Math . pow ( 10 , n ) ) - 1 ) ) ; } } public static void main ( String [ ] args ) { int n = 4 ; printPalindrome ( n ) ; } }