好的,伙计们,我有这个问题,我该如何编写代码,但中间没有空行
X
xy
xxy
xxyy
xxxyy
xxxyyy
到目前为止,以下是我的代码
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();
}
}发布于 2016-04-13 00:36:06
模式如下:
1x,0y
1x、1y
2x、1y
2x,2y...
所以你的循环应该看起来像这样:
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);https://stackoverflow.com/questions/36579054
复制相似问题