Java教程

Java打印图案5

用于打印以下模式的Java程序

程序:

public class pattern{
    public static void main(String []args){
        int lines=8;
        int i,j;
        for(i=1;i<lines;i++){
            // this loop is used to print the lines
        for(j=1;j<=lines/2;j++){
                // this loop is used to print numbers
            if(i==j){
                    System.out.print(j);
                }
                else if(i>4 && j==lines-i){
                    System.out.print(j);
                }
                else{
                    System.out.print(" ");
                }
            }
            j=j-2;
            while(j>0){
                //this loop is used to print numbers
            if(i==j){
                    System.out.print(j);
                }
                else if(i>4 && j==lines-i){
                    System.out.print(j);
                }
                else{
                    System.out.print("");
                }
                j--;
            }
            System.out.println("");
        }
    }
}
输出:
Java程序打印以下模式
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4