Saturday, 17 July 2021

A different Patter Designed in Java

 "Nice One Program"

import java.util.*;

import java.lang.*;

import java.io.*;


 /*
N - is always Even

 n = 10
****00****
***0**0***
**0****0**
*0******0*
0********0
*0******0*
**0****0**
***0**0***
****00****



for n = 4
*00*
0**0
*00*




for n = 8
***00***
**0**0**
*0****0*
0******0
*0****0*
**0**0**
***00***


for n = 14
******00******
*****0**0*****
****0****0****
***0******0***
**0********0**
*0**********0*
0************0
*0**********0*
**0********0**
***0******0***
****0****0****
*****0**0*****
******00******
 
 
 */

public class Solution  

{

public static void main (String[] args) throws java.lang.Exception

{

Scanner sc=new Scanner(System.in);

 

int n=sc.nextInt();

 

int x=0,x1=0;

int y1=n/2;

int y;

 

y=y1-1;

boolean flag=true;

for(int i=0;i<n-1;i++)

{  

//if(i==(n/2))flag=false;

for(int j=0;j<n;j++)

{

 

if((i==x && j==y) || (i==x1 && j==y1) )

{

System.out.print(" 0 ");

 

if((i==x && j==y))

{

x++;

if(x<(n/2))

y--;

else

y++;

}

else

{

x1++;

if(x1<(n/2))

y1++;

else

y1--;

}

}

else

{

System.out.print(" * ");

}

}

System.out.println();

}


}

 

}




No comments:

Post a Comment