dimanche 27 mars 2016

i am trying to create a number pattern in java. There is a slight error in the condition of the second inner for loop. I am not able to rectify it

the pattern is supposed to look like this:

 1234
 2345
 3456
 4567

i have divided it into two seperate triangles:

 1234
 234 5
 34 56
 4 567

i have done this much.Please help.

public class pattern

{
    void main(int n)
    {
        for(int i =1;i <= n; i++)
     {
        for(int j = i;j<=n;j++)
        {System.out.print(j);}
        for(int j = n+1;j<=(i*2)-1;j++)
        {System.out.print(j);}

        System.out.println();

    }


   }
 }  

Aucun commentaire:

Enregistrer un commentaire