samedi 18 juin 2016

Number Patterns In Java

Hello I wrote this code to print this form

public class Pattern{

    public static void main(String args[]) {


        for(int i=1; i<=5; i++){
            for(int j=1;j<=i;j++){
                System.out.print(j+" ");                              
            }

            for(int k=i-1;k>=1;k--){
                System.out.print(k+" ");
            }        

            System.out.println();
        }
    }
} 


1

2 3 2

3 4 5 4 3

4 5 6 7 6 5 4

5 6 7 8 9 8 7 6 5


But it was shown output

1

1 2 1

1 2 3 2 1

1 2 3 4 3 2 1

1 2 3 4 5 4 3 2 1

please guide me

Aucun commentaire:

Enregistrer un commentaire