This is our complied and working Java program for a Floyds Triangle

This was the input i got when i entered the number of rows to be 15
According to icse board the number of rows required in a floyds triangle is 5
so you can choose and vary it according to your choice
import java.util.Scanner;
class FloydTriangle
{
public static void main(String args[])
{
int n, num = 1, c, d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows of floyd's triangle you want");
n = in.nextInt();
System.out.println("Floyd's triangle :-");
for ( c = 1 ; c <= n ; c++ )
{
for ( d = 1 ; d <= c ; d++ )
{
System.out.print(num+" ");
num++;
}
System.out.println();
}
}
}
The Questions based on the program can be asked down in the comment section
Comments
Post a Comment