[英]Simple System.out printing
Ok guys I have this problem how do I code this but without empty line between 好的,我有这个问题,我该如何编码,但之间没有空行
x X
xy y
xxy xxy
xxyy xxyy
xxxyy xxxyy
xxxyyy xxxyyy
Here is my code so far 到目前为止,这是我的代码
public static void main(String[] args) {
System.out.print("x");
for(int i = 0;i<6;i++){
for(int j = 0;j<i;j++){
System.out.print("x");
}
System.out.println();
}
}
The pattern is as follows: 模式如下:
1x, 0y 1x,0y
1x, 1y 1x,1y
2x, 1y 2x,1y
2x, 2y... 2x,2y ...
So your loop should look something like this: 因此,您的循环应如下所示:
int xCount = 0;
int yCount = 0;
int total = 3;
do {
if (xCount == yCount) xCount++;
else yCount++;
for (int x = 0; x < xCount; x++) System.out.print("x");
for (int y = 0; y < yCount; y++) System.out.print("y");
System.out.println();
} while (yCount < total);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.