Print Number Pattern - 12 | Java Programs

Output:

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

Click Here For Java Online Compiler

Solution:

class NumberPattern12 {

    public static void main(String[] args) {
        int rows = 5;

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

            System.out.println();
        }

        for (int i = rows - 1; i >= 1; i--) {

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

            for (int j = i; j <= rows; j++) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}
Share This :

Related Post

avatar

good article.thank you for sharing useful info.
visit
web programming tutorial
welookups

delete 29 August 2018 at 20:13



sentiment_satisfied Emoticon