java Euler 12,三角形数的列表因子
我一直在研究欧拉问题(12),我被卡住了。我希望每个三角形的数字只显示一次,所有的因素,但我不知道如何
public class Euler12 {
public static void main(String[] args) {
int count1 = 0;
int trinumber = 0;
while (count1 < 10) {
count1++;
trinumber += count1;
for (int count2 = 1; count2 <= trinumber; count2++) {
if(trinumber % count2 == 0) {
System.out.println("trinumber: " + trinumber + " " + "factors: " + count2);
}
}
}
}
}
# 1 楼答案
将while循环更改为此
所以这个
只执行了10次,而
打印同一数字的所有因子,始终在同一行中