小编thu*_*zle的帖子

用Java打印ASCII Diamond图

我试着打印这样的东西:

+--------+
|   /\   |
|  /--\  |
| /====\ |
|<------>|
| \====/ |
|  \--/  |
|   \/   |
+--------+
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经成功地打印了图中的第一部分但是第二部分很难.

这是我打印图的第一部分的方式:

for (int fill = 0; fill <= ((2 * row - 1)); fill++) {

    if ((row % 2) == 0) {
     System.out.print("=");
    } else {
     System.out.print("-");
    }
   }
Run Code Online (Sandbox Code Playgroud)

我的第二部分是

for (int fill = 0; fill <= (n - 2 * (row - 1)); fill++) { //This is where I need help
    if ((row % 2) == …
Run Code Online (Sandbox Code Playgroud)

java algorithm ascii function

6
推荐指数
1
解决办法
520
查看次数

标签 统计

algorithm ×1

ascii ×1

function ×1

java ×1