ADS

Thursday 23 July 2020

Character Pattern in Java Looping Constructs - code analysis Quiz

Write a program to generate the following pattern. 


bbbb*bbbb

bbb***bbb

bb***** bb

b******* b

*********

b******* b

bb***** bb

bbb***bbb

bbbb*bbbb



when you run your program the output should be like 


Sample Input :

9

 

Sample Output :

bbbb*bbbb

bbb***bbb

bb***** bb

b******* b

*********

b******* b

bb***** bb

bbb***bbb

bbbb*bbbb




java source code are here:


import java.io.*;

import java.util.*;

public class My3 


{


public static void main(String[] args)

 {

Scanner sc=new Scanner(System.in);

int n,i,j,k,l;

n=sc.nextInt();

for(i=1;i<=n;i++)

{

for(j=i;j<n;j++)

{

System.out.print("b");
}


for(k=2;k<2*i+1;k=k+1)

{

System.out.print("*");

}

for(l=i;l<n;l++)

{

System.out.print("b");

}

System.out.println(" ");

}


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

{

for(j=n;j>i;j--)

{

System.out.print("b");

}

for(k=2;k<2*i+1;k=k+1)

{

System.out.print("*");

}

for(l=n;l>=i;l--)

{

System.out.print("b");

}

System.out.println(" ");

}

 }


}



Thank you for reading my article 
also Subscribe my channel


No comments:

Post a Comment

Popular Posts