Print Number Pattern - 11 | Java Programs

Output:

12345
 2345
  345
   45
    5
   45
  345
 2345
12345

Click Here For Java Online Compiler

Solution:

class NumberPattern {

    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



sentiment_satisfied Emoticon