Use JAVA to print edges, and use JAVA to print edges.
Public class Test {public static void main (String [] args) {// print (5);} public static void print (int sum) {int number = 0; for (int I = 1; I <= sum; I ++) {int emptyNumber = sum-I; // calculate the number of spaces after calculation is the total number of rows-number of rows int starNumber = 2 * I-1; // calculate the number of stars, after calculation is 2 times the number of rows-1 if (I = sum) {number = I + starNumber; // save a total number for the back-end output} for (int z = 0; z <emptyNumber; z ++) // traverse the output, obtain a triangle {System. out. print ("") ;}for (int j = 0; j <starNumber; j ++) {System. out. print ("*");} System. out. println () ;}// start to output the following part of int newrow = sum + 1; // calculate the number of rows starting with int sumrow = 2 * sum-1; // calculate the total number of new rows for (int I = newrow; I <= sumrow; I ++) {int emptyNumber = I-sum; // calculate the number of spaces, calculated as the current number of rows-the old total number of rows // calculates the number of stars, calculated by the number of stars + space + number of rows = number, that is, the number of stars in the maximum triangle + its number of rows int starNumber = number-I-emptyNumber; // traverse the output for (int z = 0; z <emptyNumber; z ++) {System. out. print ("") ;}for (int j = 0; j <starNumber; j ++) {System. out. print ("*");} System. out. println ();}}}
Result chart: