用java程序实现一道排列组合的数学题?

0-9选6个数加起来等于33的排列组合,数字可以重复。

尚方宝剑之说
浏览 888回答 2
2回答

慕莱坞森

简单粗暴的排列算法:public class BruteForceArrangement {&nbsp; public static void main(String[] args) {&nbsp; &nbsp; for (int a = 0; a < 10; a++)&nbsp; &nbsp; &nbsp; for (int b = 0; b < 10; b++)&nbsp; &nbsp; &nbsp; &nbsp; for (int c = 0; c < 10; c++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int d = 0; d < 10; d++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int e = 0; e < 10; e++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int f = 0; f < 10; f++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (a + b + c + d + e + f == 33)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);&nbsp; }}简单粗暴的组合算法:public class BruteForceCombination {&nbsp; public static void main(String[] args) {&nbsp; &nbsp; for (int a = 0; a < 10; a++)&nbsp; &nbsp; &nbsp; for (int b = a; b < 10; b++)&nbsp; &nbsp; &nbsp; &nbsp; for (int c = b; c < 10; c++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int d = c; d < 10; d++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int e = d; e < 10; e++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int f = e; f < 10; f++)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (a + b + c + d + e + f == 33)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);&nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java