Explanation :
If n=4 then output will be
1
2 3
4 5 6
7 8 9 10
Code:
import java.util.Scanner;public class FloydTriangle
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
int r = in.nextInt();
int n=0;
for(int i=0; i<r; i++)
{
for(int j=0; j<=i; j++)
{
System.out.print(++n+" ");
}
System.out.println();
}
in.close();
}
}
No comments:
Post a Comment