Write a program and output the hollow diamond in the console. The diagonal distance is 6.
Public class Diamond {public static void main (String [] args) {printHollowRhombus (6);} public static void printHollowRhombus (int size) {if (size % 2 = 0) {size ++; // calculate the diamond size} for (int I = 0; I <size/2 + 1; I ++) {for (int j = size/2 + 1; j> I + 1; j --) {System. out. print (""); // output the blank position in the upper left corner} for (int j = 0; j <2 * I + 1; j ++) {if (j = 0 | j = 2 * I) {System. out. print ("*"); // output the upper half edge of the diamond} else {System. out. print (""); // output the upper half of the diamond hollow} System. out. println (""); // line feed} for (int I = size/2 + 1; I <size; I ++) {for (int j = 0; j <I-size/2; j ++) {System. out. print (""); // the white space in the lower left corner of the output diamond} for (int j = 0; j <2 * size-1-2 * I; j ++) {if (j = 0 | j = 2 * (size-I-1) {System. out. print ("*"); // output the lower half edge of the diamond} else {System. out. print (""); // output the lower half of the diamond hollow} System. out. println (""); // line feed }}}
Effect