BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java Program to Print Right Triangle Star Pattern

Last Updated: June 22, 2022 by Chaitanya Singh | Filed Under: Java Examples

In this tutorial, we will write a java program to print the right triangle star pattern.

This is how a right triangle pattern looks like:

Number of rows = 6
Output: 
* 
* * 
* * * 
* * * * 
* * * * *  
* * * * * *

Program to print Right Triangle Star Pattern

This program is fairly easy to understand. We will work with three variables in this program, row which represents the rows of the pattern, column that represents the columns of the pattern and numberOfRows that represents the count of the rows that needs to be printed.

Logic used in the program to print Right Triangle pattern:

Here we are using nested for loop, the outer loop is for rows, which runs from 0 till numberOfRows (this is 8 in our example), this means that it will print 8 rows of stars.

The inner loop is for column that will print one star in first row, two stars in second row and so on. This is acheived by running inner loop from 0 till column <= row, this means at the first iteration when the row is 0 the inner loop will run once, second iteration when the row value is 1, the inner loop will run twice and will print two stars and so on.

public class JavaExample
{
  public static void main(String args[])
  {
    int row, column, numberOfRows=8;
    for(row=0; row<numberOfRows; row++)
    {
      for(column=0; column<=row; column++)
      {
        System.out.print("* ");
      }
      //This is just to print the stars in new line after each row
      System.out.println();
    }
  }
}

Output:

Print Right Triangle Star Pattern in Java
❮ Java TutorialJava Programs ❯

Top Related Articles:

  1. Program to Implement Merge Sort in Java
  2. Java Program to remove duplicate elements in an Array
  3. Java Program to Print Pyramid Star Pattern
  4. Java Program to Print Right Pascal’s Triangle Pattern
  5. Java Program to Print Left Pascal Triangle Pattern

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Examples

  • Check Odd-even
  • Linear Search
  • Binary Search
  • Floyd's Triangle
  • Reverse number
  • Random Number
  • first n prime numbers
  • Disp prime Numbers
  • Check Prime number
  • Palindrome String
  • Find factorial
  • Sum of elements of Array
  • Area of rectangle
  • Area of Square
  • Area of Triangle
  • Circle

Tutorials

  • Java Tutorial
  • OOPs Concepts
  • Java String
  • Exception handling
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap