Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Frequently Asked Java Program 10: Draw An Equilateral Triangle Using Stars Of Given Row

Posted on 02/19/2025 By admin

Hello Folks,

As part of Frequently Asked Java Programs In Interviews For Freshers And Experienced, in this post we will see a Java program to Draw An Equilateral Triangle Using Stars Of Given Row.

Problem statement: Draw an Equilateral Triangle using stars of given row.

Example: An Equilateral Triangle of 5 rows:

Solution:

  • Number of stars in a row is equal to row number. For example: First row has one star, Second row has two stars and so on.
  • We must need to decide number of spaces to be printed before printing first star in first row. It will help in drawing proper Equilateral Triangle.
  • Notice first row, first star is printed at column number which is equal to total number of rows. So we need to fill remaining indexes of columns with spaces.
  • Notice second row, two stars occupy columns indexes (total no of rows)   and  (total no of rows-1) . So for second row, you need to put spaces for remaining columns.
  • You must have got idea of pattern now. You need to keep reducing number of space by one for each new row.
  • If you are still confuse with how many number of spaces you need to provide, just pass (2*Total no of rows). Disadvantage of this is that your triangle will not be left aligned.
  • We will have an outer for loop, which will take care of number of rows in triangle.
  • We need to use two inner for loop. First inner loop will help us in printing spaces before printing star. Second inner for loop will help in printing stars equal to number of current row.

Java Program:

Output:

If you have any other logic of solving above problem, please comment. It is always better to know more logic.

If you like my posts, please like, comment, share and subscribe.

#HappyCoding

Uncategorized

Post navigation

Previous Post: Learn About Less Talked & Used XPath Function – position()
Next Post: Difference Between Constructor and Method in Java

Related Posts

Timeout – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
Postman Tutorial Part 36 – Export & Import Postman Collection As a JSON – Sharing Postman Collection Uncategorized
Interview Experience Uncategorized
REST Assured Tutorial 70 – Compare JSON Objects using JSONassert Library Uncategorized
image – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark