【发布时间】:2020-09-22 14:47:55
【问题描述】:
我有:
salary = 2000;
n= salary/200 = 10 //number of loops;
contribution = 0.1, 0.2, 0.3, 0.4...;
我需要创建一个 for 循环,将薪水 x 贡献的总和设为:
工资 x 贡献1 = 500x0.1 工资 x 贡献2 = 500x0.2 ...等等...
这是我班级的一个方法:
public static double pensionContribution(double salary) {
double n = salary/200;
int n_round = (int) Math.floor(n);
int start = 1;
List<Integer> n_list = IntStream.rangeClosed(start, n_round)
.boxed().collect(Collectors.toList());
double counter = 0.1;
for (int i = 0; i < n_list.size(); i++) {
System.out.println(n_list.get((int) (salary*counter)));
}
counter = counter + 0.1;
//need the sum of all values of (salary*counter)
return n_round;
}
谢谢!
【问题讨论】:
标签: java for-loop multiplication