int logarithmCeiling(int x) {
int power = 1;
int count = 0;
while (power < x) {
power = 2 *power;
count = count +1;
}
return count;
}
上面的代码是 Java 中的一种方法,用于使用 while 循环计算和返回给定正整数的下对数。我将如何为上面的循环提供不变量?即在它开始之前,每次循环体结束时,以及循环条件的否定都成立。