Computer Science, asked by sruthisiva, 1 year ago

'Java' program to print the following pattern using 'nested for loop'

1
21
321
4321
54321

Scamming will be reported

Answers

Answered by GodOfThunder123
2

The Java program is given below.

import java.util.Scanner;

public class Pattern {

public static void printPattern(int n) {

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

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

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

}

System.out.println();

}

}

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number: ");

int n = scanner.nextInt();

printPattern(n);

}

}

Here is a sample output :

Enter a number: 5

1

2 1

3 2 1

4 3 2 1

5 4 3 2 1

pls mark the brainliest

Answered by siddhartharao77
12

Sample Java Program to print the pattern:

class Brainly

{

public static void main(String args[])

{

int i,j;

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

{

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

{

System.out.print(j);

}

System.out.println();

}

}

}

Output:

1

21

321

4321

54321

Hope it helps!


Swetha02: WOW annaya!
siddhartharao77: Thanks chelli
Swetha02: :)
Similar questions