108. JAVA Program to Print Number triangle.
How does this program work?
- This program is used to print Number Triangle using java.
Here is the code
//To print Triangle Pattern
public class pattern{
public static void main(String[] args )
{
int rows = 5, k = 0, count = 0, count1 = 0;
for ( int i = 1; i <= rows; ++i )
{
for ( int space = 1; space <= rows - i; ++space )
{
System.out.print(" " );
++count;
}
while ( k != 2 * i - 1 )
{
if ( count <= rows - 1 )
{
System.out.print((i + k) + " ");
++count;
}
else
{
++count1;
System.out.print((i + k - 2 * count1) + " ");
}
++k;
}
count1 = count = k = 0;
System.out.println();
}
}
}