Algorithm for Floyd Triangle:
step 1: Set a= 1
step 2: Read row
step 3: Initialize i=0
step 4: Repeat through step-12 until i less than row
step 5: Initialize j=0
step 6: Repeat through step-10 until j less than or equals to i
step 7: Print a
step 8: If a less than 10 then print “ “
Else print “ “
step 9: a=a+1
step 10: j= j+ 1
step 11: move to new line
step 12: i=i+ 1
step 13: Exit
Here is the Java Example for Floyd Triangle:
import java.util.Scanner;
public class FloydTriangle
{
public static void main(String ar[])
{
int a=1,i,j,row;
Scanner s1=new Scanner(System.in);
System.out.println("Enter The Number of ROWS");
row=s1.nextInt();
System.out.println("\n");
for(i=0;i<row;i++)
{
for(j=0;j<=i ;j++)
{
if(a<10)
System.out.print(a+" ");
else
System.out.print(a+" ");
a++;
}
System.out.print("\n");
}
}
}