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

Table of Contents

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 456 pattern in java.

import_contacts

## Related Posts

• 05 April

### Count occurrences of Character in String in Java

Table of Contents1. Using String Library Methods2. Using Recursion3. Using Hashing ConceptUsing ArraysUsing Collections (Map) 4. Using Java 8 Features In this article, we will look at a problem: Given an Input String and a Character, we have to Count Occurrences Of character in String in java. For Example, If the Given String is : […]

• 24 December

### How to capitalize first letter in java

Learn about how to capitalize first letter in java.

• 09 October

### Java program to find first and last digit of a number

Table of ContentsAlgorithmUsing while loopUsing log() and pow() methodsUsing while loop and pow() method In this article, we are going to find first and last digit of a number in Java. To find first and last digit of any number, we can have several ways like using modulo operator or pow() and log() methods of […]

• 03 October

### Happy Number program in Java

Table of ContentsWhat is a Happy Number?Using HashsetAlgorithmExampleUsing slow and fast pointersAlgorithmExample In this article, we are going to learn to find Happy Number using Java. Let’s first understand, what is Happy Number? What is a Happy Number? A number which leaves 1 as a result after a sequence of steps and in each step […]

• 30 September

### Find Perfect Number in Java

Table of ContentsIterative approachRecursive approach In this article, we are going to find whether a number is perfect or not using Java. A number is called a perfect number if the sum of its divisors is equal to the number. The sum of divisors excludes the number. There may be several approaches to find the […]

• 28 September

### How to find Magic Number in Java

Table of ContentsWhat is a Magic Number?Algorithm for Magic NumberExample to find Magic NumberAnother Example To find Magic Number In this article, we are going to learn to find Magic Number using Java. Let’s first understand, what is Magic Number? What is a Magic Number? A number which leaves 1 as a result after a […]

## Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.