Home / Blue J / Java program for Floyds Triangle

Java program for Floyds Triangle

Java program for Floyds Triangle:

Floyd’s Triangle is one of the most popular pattern in programming lanuguage. It is not usually famous by its name as it is very easy in implementation. The diagram below shows you the floyds triangle:

Floyds triangle

// Java program for Floyd's triangle
import java.util.*;
class floyd
{
	public static void main(String args[])
	{
	int i,j,n,k=1;
	Scanner sc=new Scanner(System.in);
	System.out.print("Enter the size of floyd's triangle: NUMBER OF ROWS : ");
	n=sc.nextInt();
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=i;j++)   // since in first line you will display on 1 number in second line only two numbers so on ..
		System.out.print(k++ + "\t");  // Using /t will help in proper spacing , but ' ' will not give proper spacing
	System.out.println();        //  Changing line after every jth loop; 
	}
}
}

OUTPUT:

Java program for floyd's triangle
Java program for Floyd’s triangle

Check Also

Program to check Upper Triangular matrix

What is Upper Triangular Matrix?  An upper triangular matrix is a square matrix in which ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.