Reversible numbers | Java program to find the count of reversible numbers upto a given number n ; Function to calculate the count of reversible number ; Calculate counts of reversible number of 1 to n - digits ; All four possible cases and their formula ; for i of form 2 k ; for i of form 4 k + 3 ; for i of form 4 k + 1 no solution ; Driver function ; count up - to 9 digit numbers ( 1 billion )
import java . io . * ; class GFG { static void countReversible ( int n ) { int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { switch ( i % 4 ) { case 0 : case 2 : count += 20 * Math . pow ( 30 , ( i / 2 - 1 ) ) ; break ; case 3 : count += 100 * Math . pow ( 500 , i / 4 ) ; break ; case 1 : break ; } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int n = 9 ; countReversible ( n ) ; } }