用java 空心菱形來改的
選我正解
public class MyClass {
public static void main(String args[]) {
int hangshu = 7;
int yiban = hangshu / 2 + 1;
int yibanduo = hangshu / 2;
for(int k = 1;k <= yiban;k++){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
if(k==1){
System.out.print("*");
} else {
System.out.print("**");
}
for(int i = 1;i <= ( (k - 2) * 2 - 1);i++){
System.out.print(" ");
}
if(k==2) {
System.out.print("*");
} else if(k != 1){
System.out.print("**");
}
System.out.println();
}
for(int k = yibanduo;k >=1;k--){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
if(k==1){
System.out.print("*");
} else {
System.out.print("**");
}
for(int i = 1;i <= ( (k - 2) * 2- 1);i++){
System.out.print(" ");
}
if(k==2) {
System.out.print("*");
} else if(k != 1){
System.out.print("**");
}
System.out.println();
}
}
}