Skip to content

Commit 14ce147

Browse files
committed
feat: Print right-angled triangle number pattern using nested loops
🧠 Logic: - Accept user input `n` to define number of rows. - Outer loop (`i`) runs from 1 to `n` to represent each row. - Inner loop (`j`) runs from 1 to `i` to print increasing numbers from 1 to `i`. - After each row, print a newline to create a right-angled triangle pattern. Signed-off-by: Somesh diwan <[email protected]>
1 parent e84302d commit 14ce147

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Section8LoopAB/Loop 2.O/src/NestedLoopCC3.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import java.util.Scanner;
22

3-
public class NestedLoopCC3
4-
{
3+
public class NestedLoopCC3 {
54
public static void main(String[] args) {
65
Scanner scanner = new Scanner(System.in);
6+
System.out.println( "Enter a Number: ");
77
int n = scanner.nextInt();
88

9-
for(int i = 1; i<= n; i++)
10-
{
11-
for(int j = 1; j <= i; j++)
12-
{
9+
for(int i = 1; i<= n; i++) {
10+
for(int j = 1; j <= i; j++) {
1311
System.out.print(j + " ");
1412
}
1513
System.out.println();

0 commit comments

Comments
 (0)