Java教程

Java打印图案3

* 000 * 000 *
0 * 00 * 00 * 0
00 * 0 * 0 * 00
000 *** 000

程序:

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