Check if a larger number divisible by 36 | Java program to find if a number is divisible by 36 or not ; Function to check whether a number is divisible by 36 or not ; null number cannot be divisible by 36 ; single digit number other than 0 is not divisible by 36 ; number formed by the last 2 digits ; if number is not divisible by 4 ; number is divisible by 4 calculate sum of digits ; sum of digits is not divisible by 9 ; number is divisible by 4 and 9 hence , number is divisible by 36 ; main function
class IsDivisible { static boolean divisibleBy36 ( String num ) { int l = num . length ( ) ; if ( l == 0 ) return false ; if ( l == 1 && num . charAt ( 0 ) != '0' ) return false ; int two_digit_num = ( num . charAt ( l - 2 ) - '0' ) * 10 + ( num . charAt ( l - 1 ) - '0' ) ; if ( two_digit_num % 4 != 0 ) return false ; int sum = 0 ; for ( int i = 0 ; i < l ; i ++ ) sum += ( num . charAt ( i ) - '0' ) ; if ( sum % 9 != 0 ) return false ; return true ; } public static void main ( String [ ] args ) { String num = "92567812197966231384" ; if ( divisibleBy36 ( num ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }