我正在尝试用Java创建菱形

我目前有此代码,可让我创建菱形的左半部分。有什么办法可以完成它的镜像。或以完全不同的方式创建此形状。

What should be my diamond shape

public class diamond {

    int size = 0; //sets a starting value for size
    static int length=9;
    public static void main(String[] args) { //creates half of our diamond shape :(
        for (int i = 0; i < length; i++) {
              int j = length - 1 - i;
              for (int k = length/2; k < length; k++) { 
                  if (k == i || k == j||k==length+7+i-j) 
                      System.out.print("X"); 
                  else
                      System.out.print(" "); 
              } 
              System.out.println(""); 
            } 
    }
}
评论