Java教程

Java打印图案7

程序:

public class pattern
 {
    public static void main(String[] args) {
        int lines=4;
        int i,j;
        int space=0;
        for(i=0;i<lines;i++){
            // this loop is used to print lines
         for(j=1;j<=space;j++){
                // this loop is used to print space in a line
             System.out.print(" ");
            }
            for(j=1;j<=lines;j++){
                // this loop is used to print numbers in a line
             if(j<=(lines-i))
             System.out.print(j);
                else
             System.out.print("*");
            }
            j--;
            while(j>0){
                // this loop is used to print numbers in a line
             if(j>lines-i)
             System.out.print("*");
                else
             System.out.print(j);
                j--;
            }
            if((lines-i)>9)
            // this loop is used to increment space
         space=space+1;
            System.out.println("");
        }
    }
}
输出:
12344321
123**321
12****21
1******1
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4