-1
if (numFac == 2 || numFac ==3){
    jLabel3.setText("Prime!"); }

    for ( i=3; i <=numFac; i++ ){
        double n = numFac%i;
            if (n==1 || n!=0){
            jLabel3.setText("Prime!"); 
            break;  }

            else {
                jLabel2.setText("The Divisors of " +numFac +" are ");
                for( i = 1; i <= numFac; i++)
                    {
                    if(numFac%i == 0)
                        { jLabel3.setText(i+" "); }      
            }

}

ijlabel3. 我希望它像这样显示: System.out.print(i+" ");

4

1 回答 1

2

只需获取当前文本并附加新数字即可。

jLabel3.setText(jLabel3.getText() + i + " ");

或者,将文本存储在变量中:

String text = "";
...
text += i + " ";
jLabel3.setText(text);
于 2013-03-21T15:53:20.597 回答