逢x扣n算法

思路:将当前条目数算出当前处于哪个区间范围内,然后判断当前条目是否已经到了区间范围内的触发起始数

public static void main(String[] args) {
	/* 当前条目数 */
	int currentCount = 0;
	/* 逢 */
	int x = 3;
	/* 扣 */
	int n = 1;
	
	if(isDivisible(currentCount,x)){
		System.out.println("该条目需要扣除");
		return;
	}
	/* 最大范围 */
	int max = ((currentCount / x) + 1) * x;
	/* 最小范围 */
	int min = max - x;
	/* 起始触发数 */
	int begin = max - n;
	if (currentCount > begin) {
		System.out.println("该条目需要扣除");
		return;
	}
}

/**
 * 判断m是否能被n整除
 *
 * @param m 被除数
 * @param n 除数
 * @return
 */
private boolean isDivisible(int m, int n) {
    if (m % n == 0) {
        return true;
    }
    return false;
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值