Java教程

Java打印图案2

5432 *
543 * 1
54 * 21
5 * 321
* 4321

程序:

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