0% found this document useful (0 votes)
6 views

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)
6 views

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
You are on page 1/ 2

Q.

Display the following loop:


555555555
544444445
543333345
543222345
543212345
543222345
543333345
544444445
555555555

Answer:
import java.util.*;

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(System.in);

System.out.println("Enter a number:");

n=sc.nextInt();

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

k=c;

k=(k*10)+i;

c=k;

l=0;
System.out.print(k);

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

System.out.print(i); }

while (k!=0){

d=k%10;

if (d==1) d=0;

l=l*10+d;

k=k/10;}

System.out.print(l);

System.out.println();}

l=0;

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

d=0;

if(c!=0)k=c;

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

System.out.print(k);

if(k!=0)c=k;

l=0;

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

System.out.print(x);}

while(k!=0){

d=k%10;

l=l*10+d;

k=k/10;}

if(l!=0){System.out.print(l);}

System.out.println();}}}

You might also like