Check the divisibility of Hexadecimal numbers | Java implementation of the approach ; Function that returns true if s is divisible by m ; Map to map characters to real values ; To store the remainder at any stage ; Find the remainder ; Check the value of remainder ; Driver code
import java . util . * ; class GFG { static char [ ] CHARS = "0123456789ABCDEF " . toCharArray ( ) ; static int DIGITS = 16 ; static boolean isDivisible ( String s , int m ) { Map < Character , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < DIGITS ; i ++ ) { mp . put ( CHARS [ i ] , i ) ; } int r = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { r = ( r * 16 + mp . get ( s . charAt ( i ) ) ) % m ; } if ( r == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { String s = "10" ; int m = 3 ; if ( isDivisible ( s , m ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }