求出用1,2,5这三个数不同个数组合的和为1000的组合个数

时间:2022-09-03 10:27:58

感谢有奉献精神的人

转自:http://www.blogjava.net/yesjoy/articles/28654.html

求出用1,2,5这三个数不同个数组合的和为1000的组合个数

public class getNumbers {

public static void sums1(int temp) {
int num1 = temp / 1;
int num2 = temp / 2;
int num3 = temp / 5;
int numbers = 0;
String values;
for (int i = 0; i < num1; i++) {
for (int j = 0; j < num2; j++) {
for (int k = 0; k < num3; k++) {
if ((1 * i + 2 * j + 5 * k) == temp) {
numbers++;
values = i + "个1," + j + "个2," + k + "个5";
System.out.println("the " + numbers + " groups numbers is:" + values);
}
}
}
}
System.out.println("the numbers of group is ===>" + numbers);
}


public static void main(String[] args) {
int s = 1000;
sums1(s);
}
}