Floyd Triangle Java Program


This is Java Program to print Floyd triangle of continuous numbers based on inserted users numbers of rows.

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();
      }
   }
}

output

Enter the number of rows of floyd's triangle you want
7
Floyd's triangle :-
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28

More

For more Algorithms and Java Programing Test questions and sample code follow below links

About Saurabh Gupta

My Name is Saurabh Gupta, I have approx. 10 Year of experience in Information Technology World manly in Java/J2EE. During this time I have worked with multiple organization with different client, so many technology, frameworks etc.
This entry was posted in Algorithm, Data Structure, Java, Programming Test and tagged . Bookmark the permalink.

One Response to Floyd Triangle Java Program

  1. Pingback: Frequently Asked Algorithms and Programs in Interviews | Facing Issues On IT

Comments are closed.