I have been practicing patterns until I reached this pattern. It says print concentric squares of numbers with max layer as NxN
and Min layer 1x1
For instance, for input N=3 the desired
o/p should be
33333
32223
32123
32223
33333
I tried like
for(int i=1;i<=2*N-1;i++)
{
for(int j=1;j<=2*N-1;j++)
{
if(i==1 || i==N) --for max n min layer
System.out.print(N);
else if(j!=1 || j!=N) --for col not as max n min and rows between max n min
System.out.print(N-1);
else
System.out.print(N);
}}
I know that its wrong but I want it to be solved in a conventional way as above sample meaning step by step.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…