-
import java.util.ArrayList; import java.util.List; public class RedPacketUtil { // 请在下面的Begin-End之间按照注释中给出的提示编写正确的代码 /********** Begin **********/ // 最小红包额度 private static final int MINMONEY = 1; // 最大红包额度 private static final int MAXMONEY = 200 * 100; // 每个红包最大是平均值的倍数 private static final double TIMES = 2; /** * 参数 money * 参数 count * 返回值 List<Integer> * 功能 拆分红包 */ public List<Integer> splitRedPackets(int money, int count) { if (!isRight(money, count)) { System.out.println("红包金额不合法"); System.exit(1); } List<Integer> list = new ArrayList<Integer>(); // 红包最大金额为平均金额的TIMES倍 int max = (int) (money * TIMES / count); max = Math.min(max, MAXMONEY); for (int i = 0; i < count; i++) { int one = random(money, MINMONEY, max, count - i);