Zygodrome Number | Java implementation to check if N is a zygodrome number ; Function to check if N is an zygodrome number ; convert N to string ; Adding a space at the beginning and end of the string ; Traverse the string ; If any character is not same as prev and next then return false ; Driver code
class GFG { static boolean iszygodromeNum ( int N ) { String s = Integer . toString ( N ) ; s = ' ▁ ' + s + ' ▁ ' ; for ( int i = 1 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( i - 1 ) && s . charAt ( i ) != s . charAt ( i + 1 ) ) { return false ; } } return true ; } public static void main ( String [ ] args ) { int n = 1122 ; if ( iszygodromeNum ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }