Skip to content

Commit 8535012

Browse files
committed
feat: Print right-angled triangle star pattern using nested loops
🧠 Logic: - Take input `n` from user to define the number of rows. - Outer loop (`i`) runs from 1 to `n` to manage rows. - Inner loop (`j`) runs from 1 to `i` to print increasing stars on each row. - Print a newline after each row to form the triangle shape. Signed-off-by: Somesh diwan <[email protected]>
1 parent 189c61e commit 8535012

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
//Right angle triangle pattern
2-
31
import java.util.Scanner;
42

53
public class NestedLoopCC {
64
public static void main(String[] args) {
7-
//take input from user and print
5+
//Right angle triangle pattern.
86

97
Scanner scanner = new Scanner(System.in);
8+
System.out.println("Enter a Number: ");
109
int n = scanner.nextInt();
11-
12-
for(int i = 1; i <= n; i++)
13-
{
14-
for(int j = 1; j<= i; j++)
15-
{
10+
for(int i = 1; i <= n; i++) {
11+
for(int j = 1; j<= i; j++) {
1612
System.out.print("* ");
1713
}
18-
System.out.println(); //New line pe hoga print star
14+
System.out.println(); //New line pe Hoga print star
1915
}
2016
}
2117
}

0 commit comments

Comments
 (0)