2 回答
TA贡献1810条经验 获得超4个赞
简单粗暴的排列算法:
public class BruteForceArrangement {
public static void main(String[] args) {
for (int a = 0; a < 10; a++)
for (int b = 0; b < 10; b++)
for (int c = 0; c < 10; c++)
for (int d = 0; d < 10; d++)
for (int e = 0; e < 10; e++)
for (int f = 0; f < 10; f++)
if (a + b + c + d + e + f == 33)
System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);
}
}
简单粗暴的组合算法:
public class BruteForceCombination {
public static void main(String[] args) {
for (int a = 0; a < 10; a++)
for (int b = a; b < 10; b++)
for (int c = b; c < 10; c++)
for (int d = c; d < 10; d++)
for (int e = d; e < 10; e++)
for (int f = e; f < 10; f++)
if (a + b + c + d + e + f == 33)
System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);
}
}
添加回答
举报