📄 listing15-13_mover.java_float
字号:
// Listing 15-13. A Simple Floating-Point Calculation
public class Mover {
private int step;
private final int steps;
private final float distancePerStep;
public Mover( int distance, int steps ) {
this.steps = steps;
this.distancePerStep = (float) distance / (float) steps;
}
public int moveForward() {
this.step++;
if ( step > this.steps ) {
this.step = 0;
}
return (int) ( this.step * this.distancePerStep );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -