My first forloop is for creating triangle lines, and the second for creating coloumns.
For each line, print the first value, followed by spaces.
coloumns . coloumn
.
import java.util.Scanner;
class TriangleExample
{
public static void main(String args[])
{
int rows, number = 1, counter, j;
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of rows for triangle:");
rows = input.nextInt();
System.out.println(" triangle");
System.out.println("****************");
for ( counter = 1 ; counter <= rows ; counter++ )
{
for ( j = 1 ; j <= counter ; j++ )
{
System.out.print(number+" ");
number++;
}
System.out.println();
}
}
}