Inverted triangle

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 32:- Inverted triangle

Here's an example of how to create an inverted triangle using loops in Java:

markdownCopy code

***** **** *** ** *

javaCopy code

public class InvertedTriangle {    public static void main(String[] args) {        int n = 5;        for (int i = n; i >= 1; i--) {            for (int j = 1; j <= i; j++) {                System.out.print("*");            }            System.out.println();        }    } }

In the program above, we use two nested loops to create the inverted triangle pattern. The outer loop runs from n (5 in this case) down to 1, and the inner loop prints the appropriate number of asterisks for each row. As the outer loop decrements, the number of asterisks in each row decreases, resulting in the inverted triangle.

You can adjust the value of n to control the size of the inverted triangle and create different patterns.

6. Loops

0 Comments

Start the conversation!

Be the first to share your thoughts

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support