'Java' program to print the following pattern using 'nested for loop'
1
21
321
4321
54321
Scamming will be reported
Answers
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
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!