Pyramid Number Custom Pattern #1 in Java

thumbnail

In this tutorial, you will learn to create pyramid number custom pattern #1 in java. The source code of pyramid number pattern is show below.

package patternchallenge;
public class PatternChallenge {
    public static void main(String[] args) {
        PatternPyramid patternPyramid = new PatternPyramid();
        patternPyramid.pyramidCustomPattern1(5);
    }
}
package patternchallenge;
public class PatternPyramid {
    public void pyramidCustomPattern1(int n){
        int space = n - 1;
        for (int j = 1; j<= n; j++){
            for (int i = 1; i<= space; i++){
                System.out.print(" ");
            }
            space--;
            for (int i = 1; i <= 2 * j - 1; i++){
                System.out.print(i+"");
            }
            System.out.println("");
        }
    }
}
    1
   123
  12345
 1234567
123456789
Back To Top