HOW TO PRINT THE FOLLOWING PATTERN IN JAVA
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
Answers
In Java Programming how to print the pattern of 13 numbers , the steps are given as follows :
import java.util.*;
class np13
{
public static void main(String args[])
{
int i,j,n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of lines");
n=sc.nextInt();
for(i=n;i>=1;i--)
{
for(j=n;j>=i;j++)
{
System.out.print(j);
}
System.out.println("");
}
}
}
Note :
The above steps are in separate lines only. Because of LaTeX problem they may appear colliding. I am sorry for that.
Sample Program to Print the pattern:
class Brainly
{
public static void main(String args[])
{
for(int i = 5; i >= 1; i--)
{
for(int j = i; j <=5; j++)
{
System.out.print(j);
}
System.out.println(" ");
}
}
}
Output:
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
Hope it helps!