111. 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 = 6, coef = 1;
for ( int i = 0; i < rows; i++ )
{
for ( int space = 1; space < rows - i; ++space )
{
System.out.print( " " );
}
for ( int j = 0; j <= i; j++ )
{
if ( j == 0 || i == 0 )
coef = 1;
else
coef = coef * (i - j + 1) / j;
System.out.printf("%3d", coef );
}
System.out.println();
}
}
}