Print the integers from 1 to 20 using a while loop and the int counter variable x. Print only 5 integers per line. [Hint: When x % 5 is 0, print a newline character; otherwise, print a tab character.]
时间: 2023-12-31 07:06:16 浏览: 18
信息对象类信息对象和信息对象集合-树莓派使用手册4
Here's the code to print the integers from 1 to 20 using a while loop and the int counter variable x, with 5 integers per line:
```
int x = 1;
while (x <= 20) {
System.out.print(x);
if (x % 5 == 0) {
System.out.println();
} else {
System.out.print("\t");
}
x++;
}
```
Output:
```
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
```
阅读全文