Triangle Pattern Using Numbers in Java

Triangle pattern using numbers in java. 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

Triangle Definition

A triangle is a three-edged polygon with three vertices. It is a fundamental form in geometry. Triangle ABC denotes a triangle with vertices A, B, and C. In Euclidean geometry, any three non-collinear points define a unique triangle and, by extension, a unique plane.

For Loop Definition in Java Program

In Java, a “for” loop is an entry-controlled loop that allows a user to iteratively run a block of statement(s) for a specified number of times. The test condition supplied within the “for” loop determines the number of iterations. The Java “for” loop is one of the most basic Java loops to understand. In programming, a for loop is a conditional iterative statement that is used to check for specific criteria and then continually execute a block of code as long as those circumstances are met.

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 2 1

1 2 3 2 1 

1 2 3 4 3 2 1  

1 2 3 4 5 4 3 2 1