Floyd's Triangle in Java

 FLOYD'S TRIANGLE IN JAVA

1
2 3
4 5 6
7 8 9 10

===============================

import java.util.Scanner;
public class floyd
{
   public static void main (String args[])
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter number of rows of Floyd's triangle :");
       int row = sc. nextInt();

       int num = 1;
       for( int i=1; i<=rows; i++)
       {
          for( int j=1; j<=i; j++)
          {
              System.out.print( num+ " ");
              num++;
          }
          System.out.println();
       }
   }
}

===============================
Sample Output:
Enter number of rows of Floyd's triangle :
5

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
===============================




Post a Comment

0 Comments