import java.util.*;
import java.io.*;
class triangle
{
public static void main(String args[])throws Exception
{
int i,j;
System.out.println("enter a number");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
int n= Integer.parseInt(k.readLine());
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println("");
}
}
}
Output:
enter a number
5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
import java.io.*;
class triangle
{
public static void main(String args[])throws Exception
{
int i,j;
System.out.println("enter a number");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
int n= Integer.parseInt(k.readLine());
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println("");
}
}
}
Output:
enter a number
5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5