用while循环和计数变量X打印从1到50的奇数,要求每行只打印6个,用java编写

2025-04-28 05:20:18
推荐回答(1个)
回答1:

public class Test{
public static void main(String[] args) {
int x = 1, i = 1;
while (i < 50) {
if (i % 2 != 0) {
System.out.print(i + " ");
x++;
if (x % 6 == 0) {
System.out.println();
}
}
i++;
}
}
}