Print pyramid pattern: 1 3*2 4*5*6 pattern in java

Previous
Next

In this post, we will see how to print the following pyramid pattern.


Problem

Input : n = 4
Output :
1
3*2
4*5*6
10*9*8*7Input : n = 5
Output :
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15

Solution

If you notice the pattern we need to print odd rows in increasing order and even rows in decreasing order.
We will use two for loops and three variables to achieve this pattern.
Three variables:

  • row: It denotes to current row
  • col: It is the number which you actually prints
  • num: It actually controls the number upto which you are going to print in a row.

Java program to print 1 3*2 4*5*6 pattern in java

Time Compexity: O((n * (n + 1)) / 2)
That’s all about printing the pattern 1 3*2 4*5*6 pattern in java.

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog