Multiples of 4 ( An Interesting Method ) | An interesting XOR based method to check if a number is multiple of 4. ; Returns true if n is a multiple of 4. ; Driver method ; Printing multiples of 4 using above method
class Test { static boolean isMultipleOf4 ( long n ) { if ( n == 0 ) return true ; return ( ( ( n >> 2 ) << 2 ) == n ) ; } public static void main ( String [ ] args ) { for ( int n = 0 ; n <= 42 ; n ++ ) System . out . print ( isMultipleOf4 ( n ) ? n : " ▁ " ) ; } }