First:
Public class Test1 {public static void main (String [] args) {int n = 11; // number of rows for (int I = 0; I <n; I ++) {if (I <= (n-1)/2) {for (int j = I; j <(n-1)/2; j ++) {System. out. print ("") ;}for (int k = 0; k <2 * I + 1; k ++) {System. out. print ("*") ;}} else {for (int j = 0; j <I-(n-1)/2; j ++) {System. out. print ("") ;}for (int k = 0; k <2 * (n-I)-1; k ++) {System. out. print ("*") ;}} System. out. println ();}}}
Result:
* *** ***** ******* ******************** ********* ******* ***** *** *
Second:
Public class Test1 {public static void main (String [] args) {final int size = 5; // define the number of rows. // create a graph with 1-4 columns for (int I = 1; I <= size; I ++) {// Number of partitions in the outer loop control for (int j = I; j <size; j ++) {// This layer controls the space of the System. out. print ("") ;}for (int k = 1; k <= 2 * I-1; k ++) {// This layer controls the number of stars. System. out. print ("*");} System. out. println () ;}// print the image in the reverse direction, that is, the lower part of the image for (int I = size-1; I> = 1; I --) {for (int j = 1; j <= size-I; j ++) {System. out. print ("") ;}for (int k = 2 * I-1; k> 0; k --) {System. out. print ("*");} System. out. println ();}}}
Result:
* *** ***** **************** ******* ***** *** *
This article from the "CEO Road" blog, please be sure to keep this source http://zhaohaibo.blog.51cto.com/7808533/1287595