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 ++; // calculates 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 white space 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
}
}
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 (""); // output the white space in the lower left corner of the 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
}
}
System. out. println (""); // line feed
}
}
}
Effect