```
class Solution {
public boolean hasAlternatingBits(int n) {
int last=n%2,cur;
n=n/2;
while(n>0){
cur=n%2;
if(cur==last) return false;
last=cur;
n=n/2;
}
return true;
}
}
```

Following is the solution using Bit Manipulation by @dilyar

```
public boolean hasAlternatingBits(int n) {
int diff = n & 1;
n = n >> 1;
while (n != 0) {
int temp = n & 1;
if (diff == temp) return false;
diff = temp;
n = n >> 1;
}
return true;
}
```