In this article, we will learn about printing an inverted right-angle star pattern
Input: n = 5
Output:
* * * * * * * * * * * * * * *
Inverted Right Angle Star Pattern:
Java Code:
import java.io.*;
// Java code to demonstrate right star triangle
public class RecursiveMinds {
// Function to demonstrate printing pattern
public static void rightAngleTriangle(int n)
{
int i, j;
// outer loop to handle number of rows
// n in this case
for (i = 1; i <= n; i++) {
// inner loop to handle number of columns
// values changing according to outer loop
for (j = 1; j <= n-i+1; j++) {
// printing stars
System.out.print("* ");
}
// end-line
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
rightAngleTriangle(n);
}
}
C++ Code:
#include <iostream>
using namespace std;
// Driver code
int main()
{
int n = 5;
// ith row has i elements
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n-i+1; j++)
cout << "* ";
cout << endl;
}
return 0;
}
Python Code:
x = int(input("Enter row number= "))
for i in range(x):
for j in range(x-i):
print("* ",end='')
print("")
Time Complexity: O(n*n)
Space Complexity: O(1)
To Practice this Question on GFG
Other Questions on patterns:
Program to print square Star pattern in JAVA, C++, Python
Program to print right angle start pattern in JAVA, C++, And Python
Program to print right angle triangle number pattern in JAVA, C++, And Python
Program to print right angle triangle number pattern 2 in Java, C++, And Python

