Write a program that outputs a hollow diamond on the console and a diagonal distance of 6.
Copy Code code as follows:
public class Diamond {
public static void Main (string[] args) {
Printhollowrhombus (6);
}
public static void Printhollowrhombus (int size) {
if (size% 2 = 0) {
size++;//Calculate 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 blank in upper left corner
}
for (int j = 0; J < 2 * i + 1; j + +) {
if (j = = 0 | | | j = = 2 * i) {
System.out.print ("*");/output diamond upper half Edge
} else {
System.out.print ("");/output diamond Upper half Hollow
}
}
System.out.println (""); Line Wrap
}
for (int i = SIZE/2 + 1; i < size; i++) {
for (int j = 0; J < I-size/2; J + +) {
System.out.print ("")//output diamond bottom left corner blank
}
for (int j = 0; J < 2 * size-1-2 * i; j +) {
if (j = = 0 | | | j = = 2 * (Size-i-1)) {
System.out.print ("*");/output diamond bottom half edge
} else {
System.out.print ("");//output diamond bottom half hollow
}
}
System.out.println (""); Line Wrap
}
}
}
Effect as shown: