print
Advertisment
Advertisment

Floyd Triangle In Java

Example


import java.util.Scanner;  
class Raj   
{  
  public static void main(String[] args) {
    int n;
    int i;
    int c;
    int a=1;

    Scanner sc = new Scanner(System.in);
    System.out.print("Enter the number of rows of floyd\'s triangle to print:");
     n= sc.nextInt();
     for (i=1;i<=n ;i++ )
     {
      for ( c=1;c<=i ;c++ ) 
      {
        System.out.print(a);
        a++;
      }
      System.out.println();
      
      }
    
    }
  }

Output :

 
      
  Enter the number of rows of floyd's triangle:3
  1
  2 3
  4 5 6
  
  
Advertisment
Advertisment
arrow_upward