java WHILE循环计数
在java中,只要输入设备返回较低的值,如何让while循环运行
double leftDist = distanceSensorLeft.getDistance(DistanceUnit.MM);
double rightDist = distanceSensorRight.getDistance(DistanceUnit.MM);
leftDrive.setTargetPosition(leftDrive.getCurrentPosition() - 1500);
rightDrive.setTargetPosition(rightDrive.getCurrentPosition() + 1500);
leftDrive.setPower(0.2);
rightDrive.setPower(-0.2);
while (leftDrive.isBusy() && rightDrive.isBusy() && opModeIsActive() && rightDist/* value is smaller than previous value*/ && leftDist// value is smaller than previous value ) {
}
# 1 楼答案
您可以将最后一个值保存在变量中,然后将其与实际值进行比较