Java program to print the triangle pattern program using numbers

Java program to print the triangle pattern program using numbers. Right triangle character in a java programming language. This program will the character in java pattern program. right angle triangle program to print the numbers in triangle shape for beginners to understand the pattern in java

public class Main
{ 
public static void main(String[] args) 
{ 
int i, j, lines=5; 
for (i = 1; i <= lines; i++) 
{ 
for (j = 1; j <= i; j++) 
{ 
System.out.print(j+" "); 
} 
for (j = i-1; j >= 1; j--) 
{ 
System.out.print(j+" "); 
} 
System.out.println(); 
} 
} 
} 

 

Output:

1                                                                                                                               

1 2 1                                                                                                                           

1 2 3 2 1                                                                                                                       

1 2 3 4 3 2 1                                                                                                                   

1 2 3 4 5 4 3 2 1