Java教程

Java打印图案1

Java打印螺旋模式

程序:

public class pattern
 {
    public static void main(String[] args) {
        int lines=4;
        int i,j,k,l;
        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("");
        }
    }
}
输出:
用于在控制台上打印以下螺旋形图案的Java程序
用于在控制台上打印以下螺旋图案的Java程序
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4