A collection of different Pyramid patterns in Java.
The first pattern is the one from image above - this is a pyramid with numbers. Each number is printed exactly the number of times it denotes - means 1 is printed once, 2 is printed twice, 3 is printed thrice and so on.
There is leading white space of rows-i
where i is the number of rows - for e.g in first row there is 4 white spaces,
3 in second and so on.
There is a function created for creating the login for the pattern, which is common in all cases, and one function which only prints
The second pattern is the image above - this is a pyramid pattern where numbers keep increasing on each row.
There is leading white space of rows-i
where i is the number of rows - for e.g in first row there is 7 white spaces,
6 in second and so on.
Now for the numbers, you can see the with each row the count of numbers are increasing - so we have the logic where this happens.
The third pattern is the one from image above - this is a pyramid with *
instead of numbers.
Each *
is printed exactly the number of times it denotes - means 1 is printed once, 2 is printed twice, 3 is printed
thrice and so on.
There is leading white space of rows-i
where i is the number of rows - for e.g in first row there is 4 white spaces,
3 in second and so on.
The logic for printing *
is same as pattern 1, in place of numbers, you print the character.
The fourth pattern is one from the image above - this is a pyramid where the numbers decrease up to mid and then increase from the mid.
This is the inverted star pattern - just the opposite of the one from Pattern 3.
The first row of the stars has the number that you enter for the rows - let it be rows
. With each increasing row,
the number of the stars decrease by 2 and whitespace increase by 1.