Home >>Java Programs >Java program to print the following pattern
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
In this example, we will see a Java program through which we will try to print the above-given pattern on the console.
Algorithm:
public class Main
{
public static void main(String[] args)
{
int i ,j;
int n = 5;
for(i = n; i>0 ; i-- )
{
for(j = 1; j<=i ; j++)
{
System.out.print(j);
}
System.out.println("");
}
}
}