In C++, 1 is treated as true and 0 is treated as false. So, internal conversion is possible in C++. But can this be possible in Java? Can we convert int to boolean or boolean into int as per our need in Java?
For Example, for this problem on GeeksForGeeks, the C++ code might look like -
class Solution {
public:
int findPosition(int N) {
if((N & (N -1)) or (N == 0)) return -1;
return log2(N) + 1;
}
};
How can write the same type of solution in Java? Thank You.