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+" "); }
}
}
我在i
中显示jlabel3
时遇到问题。我希望它显示如下:System.out.print(i+" ");
答案 0 :(得分:2)
只需获取当前文字并附加新号码。
jLabel3.setText(jLabel3.getText() + i + " ");
或者,将文本存储在变量中:
String text = "";
...
text += i + " ";
jLabel3.setText(text);