java打游空菱形代码 java打游空菱形代码怎么写

java 怎样写出一个菱形程序?空心和实心java打印菱形通过二维数组来打印,实例如下:
int hangshu = 11;
int yiban = hangshu / 21;
int yibanduo = hangshu / 2;
System.out.println("空心菱形:");
for(int k = 1;k = yiban;k){
for(int i = 1;i = (yiban - k);i){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i = ( (k - 2) * 21);i){
System.out.print(" ");
}
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(" ");
}
System.out.print("*");
for(int i = 1;i = ( (k - 2) * 21);i){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
System.out.println("实心菱形:");
for(int i = 1;i = hangshu;i){
if(i = hangshu/21){
for(int k = 1;k = hangshu/21- i;k){
System.out.print(" ");
}
for(int k = 1;k = i;k){
System.out.print("* ");
}
System.out.println();
}else{
for(int k =1;k = (i -(hangshu/21));k){
System.out.print(" ");
}
for(int k = 1;k = (2 *(hangshu/21) - i);k){
System.out.print("* ");
}
System.out.println();
}
}
结果如下:
java打印空心菱形Java利用for循环输出空心菱形java打?

    推荐阅读