Check if a number is a Mystery Number | Java implementation of above approach ; Finds reverse of given num x . ; if found print the pair , return
class GFG { static int reverseNum ( int x ) { String s = Integer . toString ( x ) ; String str = " " ; for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { str = str + s . charAt ( i ) ; } int rev = Integer . parseInt ( str ) ; return rev ; } static boolean isMysteryNumber ( int n ) { for ( int i = 1 ; i <= n / 2 ; i ++ ) { int j = reverseNum ( i ) ; if ( i + j == n ) { System . out . println ( i + " ▁ " + j ) ; return true ; } } System . out . println ( " Not ▁ a ▁ Mystery ▁ Number " ) ; return false ; } public static void main ( String [ ] args ) { int n = 121 ; isMysteryNumber ( n ) ; } }