In Floyd triangle there are n integers in the nth row and a total of (n(n+1))/2 integers in n rows. We take input as number of rows user want to print.
Here is the source code of the Java Program to Display Floyd’s Triangle. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
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++ )
$ javac Floyd.java $ java Floyd Enter the number of rows of floyd's triangle you want 5 Floyd's triangle :- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Sanfoundry Global Education & Learning Series – 1000 Java Programs.