import acm.program.*;
public class Practice3 extends ConsoleProgram
{
public static int powersOf2(int k) {
int x = 0;
while (k < 1000) {
x = k;
k *= 2;
}
return x;
}
public void run()
{
println(powersOf2(1));
println(powersOf2(0));
println(powersOf2(2));
println(powersOf2(-1));
println(powersOf2(3000));
}
我不认为我真的从powersOf2
. 运行程序时只显示 512。如果我按 each 运行它println
,它会给我:
512
none
512
none
0
有什么不对?或价值观是正确的?