Check if a number is jumbled or not | Java code to check if a number is jumbled or not ; Function to check if a number is jumbled or not ; Single digit number ; Checking every digit through a loop ; All digits were checked ; Digit at index i ; Digit at index i - 1 ; If difference is greater than 1 ; Number checked ; Driver code ; - 1234 to be checked ; 287 to be checked
import java . io . * ; class GFG { static boolean checkJumbled ( int num ) { if ( num / 10 == 0 ) return true ; while ( num != 0 ) { if ( num / 10 == 0 ) return true ; int digit1 = num % 10 ; int digit2 = ( num / 10 ) % 10 ; if ( Math . abs ( digit2 - digit1 ) > 1 ) return false ; num = num / 10 ; } return true ; } public static void main ( String [ ] args ) { int num = - 1234 ; if ( checkJumbled ( num ) ) System . out . println ( " True ▁ " ) ; else System . out . println ( " False ▁ " ) ; num = - 1247 ; if ( checkJumbled ( num ) ) System . out . println ( " True ▁ " ) ; else System . out . println ( " False ▁ " ) ; } }