Home Java Example Java Core Java Program Floyd's Triangle



Java Program Floyd's Triangle
Posted on: February 4, 2013 at 12:00 AM
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 :

1
2 3
4 5 6
7 8 9 10

Source Code

FloydTriangleExample.java

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

Output :

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

Download Source Code

Related Tags for Java Program Floyd's Triangle:


More Tutorials from this section

Ask Questions?    Discuss: Java Program Floyd's Triangle  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.