Computer Science, asked by nallasurya23, 5 months ago

write a program in java to display the pattern.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Answers

Answered by SP85
12

This type of pattern is also K n own as pyramid pattern

So let's begin

public class HalfPyramid {

public static void main(String[] args) {

int rows = 5;

for (int i = 1; i <= rows; ++i) {

for (int j = 1; j <= i; ++j) {

System.out.print(j + " ");

}

System.out.println();

}

}

}

Got your ans mark brainliest

Answered by anindyaadhikari13
5

Question:-

➡ Write a program in Java to display the pattern.

Program:-

import java.util.*;

class Pattern

{

public static void main(String args[])

{

Scanner sc=new Scannerj(System.in);

System.out.print("Enter the number of rows: ");

int n=sc.nextInt(),i,j;

for(i=1;i<=n;i++)

{

for(j=1;j<=i;j++)

System.out.print(j+" ");

System.out.println();

}

}

}

Similar questions