ADS

Thursday 23 July 2020

Character Pattern in Java part-2 Looping Constructs - code analysis Quiz

Write a program to generate the following pattern.

*********

b******* b

bb***** bb

bbb***bbb

bbbb*bbbb


Input and Output Format:


Input consists of a single integer that corresponds to n, the number of rows. n is always an odd number.


 


Sample Input :


5


 


Sample Output :


*********


b******* b


bb***** bb


bbb***bbb


bbbb*bbbb



Read also  Print Reverse Character Pattern of this :


java Program source code:



import java.io.*;

import java.util.*;

class Main

{

public static void main(String[]args)

{


int n,i,j,k,l;

Scanner s=new Scanner(System.in);

n=s.nextInt();

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

{

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

{

System.out.println("b");

}

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

{

System.out.println("*");

}

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

{

System.out.println("b");

}

System.out.println("\n");


}


}

}


Read more: Lucas Sequence:


Thank you 


1 comment:

Popular Posts