Computer Science, asked by Anonymous, 5 months ago

WAP IN JAVA to print the following pattern:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1​

Answers

Answered by BrainlyProgrammer
2

Question:-

  • to print in java the following pattern

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1​

Answer:

import java.util.*;

class codeme

{

   public static void main (String ar[])

   {

       int i,j;

       for (i=1;i<=5;i++)

       {

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

           {

               System.out.print(j+" ");

           }

           System.out.println();

       }

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

       {

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

           {

               System.out.print(j+" ");

           }

           System.out.println();

       }

   }

}

  • For verification see the above attachment.

Attachments:
Similar questions