我正在尝试将1平方的值打印出10,10平方乘10,100平方乘以10等等。但是在我的输出中,我继续将值设置为double而不是int(整数),这是我应该做的。
public class PowerGenerator {
int factor;
public PowerGenerator(int aFactor) {
factor = aFactor;
}
public double nextPower() {
if(factor < 0.9) {
factor = 1.0; // This is where the compiler has an error.
return 1;
}
factor = factor * 10;
return factor;
}
public static void main(String[] args) {
PowerGenerator test= new PowerGenerator(0);
for(int i = 0; i < 12; i++) {
System.out.println(test.nextPower());
}
}
}
我的代码输出是:
1.0
10.0
100.0
1000.0
10000.0
100000.0
1000000.0
1.0E7
1.0E8
1.0E9
1.0E10
1.0E11