If you have any query feel free to chat us!
Happy Coding! Happy Learning!
Here's an example of how to create an inverted triangle using loops in Java:
markdownCopy code*****
****
***
**
*
javaCopy codepublic 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.
Under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use.
Comments: 0