How do I use Java Stream given an integer N of which actions are, if N is odd, subtract 1 from it and if N is even, divide it by 2 until N becomes 0?
This is my working code using procedural style:
public static int solution(int num) {
int counter = 0;
while(num != 0) {
num = (num % 2 == 0) ? num / 2 : num - 1;
counter++;
}
return counter;
}