0% found this document useful (0 votes)
13 views2 pages

Nestedloop Pattern

Code of a pattern

Uploaded by

pradyumnabetall
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Nestedloop Pattern

Code of a pattern

Uploaded by

pradyumnabetall
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q.

Display the following loop:


555555555
544444445
543333345
543222345
543212345
543222345
543333345
544444445
555555555

Answer:
import [Link].*;

public class P3{

public static void main(){

int i,j,x,y,n;

int k=0,l=0,m,c=0,d;

Scanner sc = new Scanner([Link]);

[Link]("Enter a number:");

n=[Link]();

for(i=n;i>=1;i--){

k=c;

k=(k*10)+i;

c=k;

l=0;
[Link](k);

for(j=1;j<=(i*2)-3;j++){

[Link](i); }

while (k!=0){

d=k%10;

if (d==1) d=0;

l=l*10+d;

k=k/10;}

[Link](l);

[Link]();}

l=0;

for(x=2;x<=n;x++){

d=0;

if(c!=0)k=c;

if(k!=0)k=(k-(x-1))/10;

[Link](k);

if(k!=0)c=k;

l=0;

for(y=1;y<=((x+1)*2)-5;y++){

[Link](x);}

while(k!=0){

d=k%10;

l=l*10+d;

k=k/10;}

if(l!=0){[Link](l);}

[Link]();}}}

You might also like