在Java中使用for循环的麻烦

aki*_*kif 5 java loops for-loop

因为我非常喜欢编程,我喜欢在空闲时间编程所以我试图创建一个输出看起来像x的代码.像这样的东西.

x    x
 x  x
  x
 x  x
x    x
Run Code Online (Sandbox Code Playgroud)

所以我希望用户输入"x"的高度.这是我到目前为止的代码,我真的不知道如何继续前进.我只需要一个提示或者是否有人可以告诉我哪里出错了.

import java.util.Scanner;    
    public class x{
    public static void main(String[] args){
    Scanner kbd = new Scanner(System.in);
    int height;    
    System.out.print("Enter the height of the X:   " );             
    height = kbd.nextInt();
    for (int i = 1; i <= height; i++){                        
      for (int j = 1; j <= height; j++) {                            
        if(i ==j || j+i == height + 1)                               
            System.out.println("x");                            
        else                            
            System.out.print(" ");
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Dan*_* S. 5

两个变化: