Computer Science, asked by TreeshaBiswas, 2 months ago

print the above pattern using Java programming​

Attachments:

Answers

Answered by udayagrawal49
3

Answer: The required Java program is :-

public class Main {

public static void main(String[] args) {

    int i,j;

    for(i=1;i<=4;i++) {

        for (j=1;j<=4-i;j++) {

            System.out.print(" ");

        }

        for(j=1;j<=i;j++) {

            System.out.print(j);

        }

        for(j=i-1;j>=1;j--) {

            System.out.print(j);

        }

        System.out.println();

    }

    for(i=3;i>=1;i--) {

        for(j=1;j<=4-i;j++) {

            System.out.print(" ");

        }

        for(j=1;j<=i;j++) {

            System.out.print(j);

        }

        for(j=i-1;j>=1;j--) {

            System.out.print(j);

        }

        System.out.println();

    }

   }

}

Note :-

The above program is saved in a file named Main.java

Also, try-catch block can be used to avoid errors.

Similar questions