输出一个看起来像给定尺寸的英国国旗的图案的程序

Program that outputs a pattern that looks like the union jack given the size

所以我的程序应该输出一个类似英国国旗的模式,例如:

3 =      ,     7 = 

0X0            0  X  0
XXX             0 X 0 
0X0              0X0
               XXXXXXX
                 0X0
                0 X 0
               0  X  0

到目前为止,这是我的代码... 有人能找出问题所在吗?我真的不知道出了什么问题,它输出的模式很相似,但空格都错了

import java.util.*;
public class uj {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int input;
        int counter2=1;
        int counter1=1;

        do{
            System.out.println("Enter size(must be odd): ");
            input = sc.nextInt();
        }while(input/2==0);

        int half = (input/2)+1;
        while(counter1<=input+1){
            while(counter2<=input+1){
                if(counter2==counter1 || counter2==(input-counter1)){
                    System.out.print("0");
                }else if(counter2==half && counter1!=half){
                    System.out.print("x");
                }else if(counter1==half){
                    System.out.print("x");
                }else{
                    System.out.print(" ");

                }
                counter2++;
            }
            System.out.println("");
            counter1++;

            counter2=0; 
        }
    }
} 

最好打印一个 NxN 正方形的字符。

public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int input;
  do {
    System.out.println("Enter size(must be odd): ");
    input = sc.nextInt();
  } while(input%2 == 0);

  int half = input/2 + 1;
  for( int iRow = 1; iRow <= input; ++iRow ){
    for( int iCol = 1; iCol <= input; ++iCol ){
      // Highest precedence: middle row, middle column
      if( iRow == half || iCol == half ){
        System.out.print( 'X' );
      } else
      // next, the diagonals
      if( iRow == iCol || input - iCol + 1 == iRow ){
        System.out.print( '0' );
      } else {
        // the rest is white space
        System.out.print( ' ' );
      }
    }
    System.out.println();
  }
}