Coding Fun Java 4 variables approach for pattern programming ( JAVA)

4 variables approach for pattern programming ( JAVA)





Code is given in the comment section.

Tags: , , , , , , , , , ,

1 thought on “4 variables approach for pattern programming ( JAVA)”

  1. Code:

    import java.util.*;

    class Example

    {

    public static void main(String args[])

    {

    Scanner obj=new Scanner(System.in);

    int a=obj.nextInt();

    int l=a*2;

    int b[]=new int[l];

    int temp=0;

    for(int i=1;i<=a;i++)

    {

    b[i-1]=i;

    temp++;

    }

    for(int i=a;i>=1;i–)

    b[temp++]=i;

    int x=a-1;

    int y=a;

    System.out.println();

    for(int i=1;i<=a;i++)

    {

    for(int j=0;j<=2*a-1;j++)

    {

    if(j<=x || j>=y)

    System.out.print(b[j]+" ");

    else

    System.out.print(" ");

    }

    x–;

    y++;

    System.out.println();

    }

    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *