标题:打印图形
小明在X星球的城堡中发现了如下图形和文字:
rank=3
*
* *
* *
*
* *
* *
* * * *
* *
* * * *
* * * *
* * * * * * * *
* *
* * * *
* * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
小明在X星球的城堡中发现了如下图形和文字:
rank=3
*
* *
* *
* * * *
*
* *
* *
* * * *
* *
* * * *
* * * *
* * * * * * * *
* *
* * * *
* * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
public class Main{
static void f(char a[][], int rank, int row, int col)
{
if(rank==1){
a[row][col] = '*';
return;
}
int w = 1;
for(int i=0; i<rank-1; i++) w *= 2;
f(a, rank-1, row, col+w/2);
f(a, rank-1, row+w/2, col);
f(a, rank-1, row+w/2, col+w);
}
public static void main(String[] args)
{
int N=40;
char a[][]=new char[N][N];
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++) a[i][j] = ' ';
f(a,5,0,0);
for(i=0; i<N; i++){
for(j=0; j<N; j++) System.out.printf("%c",a[i][j]);
System.out.printf("\n");
}
}
}