标签:public 长度 oid 倒序输出 string 输出 for class 打印
1五行五列的*
*****
*****
*****
*****
*****
public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { System.out.print("*"); } System.out.println("*"); } }
2.
*
**
***
****
*****
public static void main(String[] args) { for (int i = 0; i < 5; i++) { for (int j = 0; j <= i; j++) { System.out.print("*"); } System.out.println(); } }
3.
*
**
***
****
*****
public static void main(String[] args) { for (int i = 0; i < 5; i++) { for (int j = 0; j < (5-i-1); j++) { System.out.print(" "); } for (int j = 0; j <= i ; j++) { System.out.print("*"); } System.out.println(); } }
4.
*
***
*****
*******
*********
public static void main(String[] args) { for (int i = 1; i <= 5; i++)//正序输出上半部分 { for (int j = 1; j <= 5 - i; j++) { System.out.print(" "); } for (int k = 1; k <= i * 2 - 1; k++) { System.out.print("*"); } System.out.println(); } }
6.
*
***
*****
*******
*****
***
*
public static void main(String[] args) { int lay; lay = 7;//菱形的总长度 for(int i = 1; i <= (lay+1)/2; i++)//正序输出上半部分 { for(int j = 1; j <=(lay+1)/2-i ; j++)//输出空格 { System.out.print(" "); } for(int k = 1; k <= i*2-1; k++) { System.out.print("*"); } System.out.println();//换行 } for(int i =(lay+1)/2-1;i >= 1; i --)//倒序输出下半部分 { for(int j = 1; j <= (lay+1)/2-i; j++)//输出空格 { System.out.print(" "); } for(int k = (lay+1)/2-i; k <=(lay+1)/2-2+i; k ++)//(lay+1)/2-1即为下半个三角形 { System.out.print("*"); } System.out.println(); } }
标签:public 长度 oid 倒序输出 string 输出 for class 打印
原文地址:https://www.cnblogs.com/smxbo/p/10629201.html