mardi 29 octobre 2019

Print the following pattern

I heed help with a pattern.

I've managed to write the code for the top part. I need help with the bottom one.

public class P5na
{
    public static void main()
 {
     System.out.println();
     int i,j;
        for(i=5;i>=1;i--)
        {
            for(j=1;j<=5;j++)
            {
                if(j<=i)
                 System.out.print(j);

                else
                 System.out.print(" ");
            }
            for(j=4;j>=1;j--)
            {
                if(j<=i)
                 System.out.print(j);
                else
                 System.out.print(" ");
            }
            System.out.println();
        }
    }
}

Required Output:

123454321
1234 4321
123   321
12     21
1       1
12     21
123   321
1234 4321
123454321

Initial Output:

123454321
1234 4321
123   321
12     21
1       1

Aucun commentaire:

Enregistrer un commentaire