• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
September 16, 2022 |4.2K Views

Java program to print Trapezium Pattern

  Share  3 Likes
Description
Discussion

In this video, we will write a program to print Trapezium Pattern in Java.

The trapezium pattern is a diagram that is a convex quadrilateral. It has exactly one pair of opposite sides which is parallel to each other. Also, the trapezium is a two-dimensional shape. 

Examples: 
Input:
Output :
1*2*3*4*17*18*19*20
     5*6*7*14*15*16
           8*9*12*13
               10*11

Algorithm to Print Trapezium Pattern : 
Step 1. Input num which indicates the number of lines. 
Step 2. In the second step, we are just diving the pattern into 2 halves i.e LHS part and the RHS part. 
Step 3. Now in the last step, we are combining LHS and RHS to get the complete pattern of the trapezium.

Here we see time and space complexity as well: 
Time complexity: O(n2)
Space complexity: O(1)