Monday , December 18 2017
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:

Also See:   c program for pattern#12
Java program for floyd's triangle
Java program for Floyd’s triangle

Check Also

Java program to implement polymorphism

Java program to implement polymorphism: Polymorphism is a technique in java with which you can ...

Leave a Reply

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