Computer Science, asked by sonugungun630, 9 months ago

Write a program to display the given patterns in java
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

Answers

Answered by dadapp67
10

public class Pattern {

public static void main(String[] args) {

int rows = 5;

for(int i = rows; i >= 1; --i) {

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

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

}

System.out.println();

}

}

}

HOPE IT HELP YOU

Answered by anindyaadhikari13
7

Question:-

Write a Java program to print the following pattern.

54321

4321

321

21

1

Program:-

import java.util.*;

class Pattern

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

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

int n=sc.nextInt();

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

{

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

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

System.out.println();

}

}

}

Take the input from the user and you will get the output.

Similar questions
Physics, 1 year ago