Java Euler 12,三角形数的列表因子

Java Euler 12,三角形数的列表因子,java,Java,我一直在研究欧拉问题12,我被卡住了。我希望每个三角形的数字只显示一次,所有的因素,但我不知道如何 public class Euler12 { public static void main(String[] args) { int count1 = 0; int trinumber = 0; while (count1 < 10) { count1++; trinumbe

我一直在研究欧拉问题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);
                }
            }
        }
    }      
}

将while循环更改为此

while (count1 < 10) {
    count1++;
    trinumber += count1;
    System.out.print("trinumber: " + trinumber + ", factors: ");
    for (int count2 = 1; count2 <= trinumber; count2++)
        if (trinumber % count2 == 0)
            System.out.print(count2 + ", ");
    System.out.println();
}
只执行了10次,而

    System.out.print(count2 + ", ");
打印同一数字的所有因子,始终在同一行中

    System.out.print(count2 + ", ");