import java.util.Random;
import java.util.Scanner;
public class HongBao {
public static void main(String[] args) {
System.out.println("=======微信红包=====");
Scanner scanner = new Scanner(System.in);
System.out.println("请输入红包的总金额:");
double total = scanner.nextDouble();
System.out.println("请输入红包的总个数:");
int baoNum = scanner.nextInt();
Random random = new Random();
double min = 0.01;
for (int i = 1; i < baoNum; i++) {
double max = total - (baoNum - i) * min;
double bound = max - min;
double sort = (double) random.nextInt((int) (bound * 100)) / 100;
double bao = sort + min;
total = total - bao;
System.out.println(String.format("第" + i + "个红包的数值为:" + String.format("%.2f", bao)));
}
System.out.println("第" + baoNum + "个红包的数值为:" + String.format("%.2f", total));
}
}
|