for 小实例
使用for循环
打印一个9行的 实心菱形
{
int r=7;
int t=0;
for(int i=0;i<=5;i++){
for (int j1 = 1; j1 <=5-i; j1++) {
System.out.print(" ");
}
t=2*i-1;
for (int j = 0; j < t; j++) {
System.out.print("*");
}
System.out.println();
}
for (int y = 0; y<=3; y++) {
for (int i1 = 1; i1 <=y+1; i1++) {
System.out.print(" ");
}
r=7-(2*y);
for (int z = 0; z < r; z++) {
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
输出结果:
~~~java
*
***
*****
*******
*********
*******
*****
***
*