我正在做一项家庭作业,这要求我制定一个重要的计划。 给出的例子是
int i = 1; while (i <= 5){ System.out.println(i); i++; }现在,我有一切工作,除了我需要将输出分配给标签,我有什么。
while (start <= end) { outputLabel.setText(String.valueOf(start)); start++; } }当我运行它时,显示的只是结束号码。 我认为这是因为标签在每次循环时都会重置,而不是显示所有循环。 如何让它显示每个数字而不是最后一个数字?
I'm working on a homework assignment, which requires me to make a program that counts. The example given is
int i = 1; while (i <= 5){ System.out.println(i); i++; }Now, I have everything working, except I need to assign the output to a label, what I have is.
while (start <= end) { outputLabel.setText(String.valueOf(start)); start++; } }When I run it, all it displays is the end number. I figure this is because the label is reset every time it loops, instead of displaying all the loops. How can I make it show every number instead of just the last number?
最满意答案
您需要将数字添加到标签的文本中:
outputLabel.setText(outputLabel.getText() + start);System.out.println对我来说根本没有意义。
You will need to add the number to the text of the label:
outputLabel.setText(outputLabel.getText() + start);The System.out.println doesn't make sense for me at all.
更多推荐
发布评论