Home >>Java Programs >Java program to print the given pattern
0
909
89098
7890987
678909876
56789098765
4567890987654
345678909876543
23456789098765432
1234567890987654321
In this example we will see a Java program in which we will try to print the above given pattern on the console.
Algorithm:
public class Main
{
public static void main(String []args)
{
int lines=10;
int i,j;
int count;
for(i=1;i<=lines;i++)
{
count=0;
for(j=1;j<lines;j++)
{
if(count<i-1){
if(!(j<lines-i+1))
{
System.out.print(j);
count++;
}
}
}
System.out.print("0");
count=0;
for(--j;j>=1;j--){
if(count<i-1){
System.out.print(j);
count++;
}
}
System.out.println("");
}
}
}