Gray code check in java