listing15-13_mover.java_float

来自「着几乎所有智能机厂商都将有自己配套的App Store,甚至并非智能手机制造商的」· JAVA_FLOAT 代码 · 共 23 行

JAVA_FLOAT
23
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?