关于#java#的问题:读入正整数n,打印边长为n的

编写程序,读入正整数n,n<10,打印边长为n的,用*组成的菱形轮廓。例如n = 3时
*


public class Main {
    public static void main(String[] args) {
        int n = new Scanner(System.in).nextInt();
        for(int i = 0; i < n; i++){
            for(int j = n - i - 1; j > 0; j--){
                System.out.print(" ");
            }
            System.out.print("*");
            for(int j = 0; j < (i - 1) * 2 + 1; j++){
                System.out.print(" ");
            }
            if(i != 0) System.out.print("*");
            System.out.println();
        }
        for(int i = 1; i < n; i++){
            for(int j = 0; j < i; j++){
                System.out.print(" ");
            }
            System.out.print("*");
            for(int j = 0; j < 2 * n - i * 2 -3 ; j++){
                System.out.print(" ");
            }
            if(i < n - 1) System.out.print("*");
            System.out.println();
        }
    }
}

若对你有帮助,请采纳一下哈!!!