Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Java Example Java Core Java Program Floyd's Triangle

Related Tutorials


Share on Google+Share on Google+

Java Program Floyd's Triangle

In this section you will read about how to write a Java program to print Floyd's triangle.

Java Program Floyd's Triangle

In this section you will read about how to write a Java program to print Floyd's triangle.

This tutorial is about printing a Floyd's triangle in Java. Here you will learn about all the steps for creating the Floyd's triangle in Java.

Before writing a Java program for displaying Floyd's triangle, first we will discuss what is Floyd's triangle.

Floyd triangle is named after a computer scientist Robert Floyd. This triangle is a right angled triangle made up by the array of natural numbers. Rows of this triangle contains the consecutive numbers started from the number '1' in the top left corner. And the sum of n'th row is n(n^2+1)/2.

Floyd's triangle should be look like below :

2 3
4 5 6
7 8 9 10

Source Code

public class FloydTriangleExample
public static void main(String[] args) throws Exception 
int k=0;
for(int i = 0; i <5; i++)
for(int j = 0; j <i; j++)
k = k + 1;
System.out.print(" ");

Output :

When you will execute the above example you will get the output as follows :

Download Source Code


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 4, 2013

Related Tutorials

Discuss: Java Program Floyd's Triangle  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image