/*
打印空的菱形
*/
class Diamond1 {
public static void main(String[] args) {
char [][]c=new char[7][7];
for (int i=0;i<c.length ;i++ ){
for (int j=0;j<c[i].length ;j++ ) {
if(j==-i+3||j==i+3||(j==-i+9&&i<7&&i>3)||j==i-3) //条件语句输出*,
c[i][j]='*';
else
c[i][j]=' ';//否则输出空格
}
}
for (int i=0;i<c.length ;i++ )
{ for (int j=0;j<c[i].length ;j++ )
System.out.print(c[i][j]);
System.out.println();}
}
}
|
|