Computer Science, asked by arpitadey0125, 2 months ago

Print the pattern in java
1
21
321
4321
54321​

Answers

Answered by MrTSR
3

Sample Java program to print the pattern:

import java.util.*;

public class P2 {

public static void main(String[] args)

{

Scanner s = new Scanner (System.in);

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

int row = s.nextInt();

for (int i=1; i<=row; i++)

{

for(int j=i; j>=1; j--)

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

System.out.println();    

}

}

}

Output:

Enter number of rows:  5

1  

2 1  

3 2 1  

4 3 2 1  

5 4 3 2 1

*Refer attachment for output*

Attachments:
Similar questions