ADS

Thursday 23 July 2020

Character Pattern in Java (Looping Constructs - code analysis Quiz )

Character Pattern in Java :

Print following Pattern using JAVA Programming Language.

Q:Write a program to generate the following pattern.

bbbb*bbbb

bbb***bbb

bb***** bb

b******* b

********* 



Input and Output Format:


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

 

Sample Input :

5

 

Sample Output :

bbbb*bbbb

bbb***bbb

bb***** bb

b******* b

*********
  
  java code for character pattern:
---------------------------------

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=1;i<=n;i++)
{
  for(j=1;j<n;j++)
  {
   System.out.println("b");
  }
  for(k=2;k<2*i+1;k++)
  {
   System.out.println("*");
  }
 for(l=i;l<n;l++)
  {
   System.out.println("b");
  }
System.out.println("\n");

}
}
}


 Thank you 

No comments:

Post a Comment

Popular Posts