Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文本框,我在其中获取how many number do you want to print?Now 的值 我的问题是,我如何使用 for 循环,以便我要打印的数字等于我从文本框中得到的数字?还有一件事是我只想在一行中打印三个数字。
how many number do you want to print?
即,如果我在文本框中输入 14,结果将如下所示。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
假设您从文本框中捕获了值并将其保存到一个数字中:
这将打印出您指定的数字:
public void print_numbers(int num) { int counter = 1; while ( counter <= num ) { System.out.print(counter); if ( counter % 3 == 0 ) { System.out.print("\n"); } counter++; } }