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

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?