dimanche 5 juin 2016

How to print Floyd's triangle in Java - Example Tutorial

In the last article, I have taught you how to print Pascal's triangle and in today's article I'll teach you how to print Floyd's triangle in Java program. Floyd's triangle is easier to print than Pascal's triangle because you don't need to take care of formatting the numbers as Floyd's triangle is a right angle triangle. It is named after American computer scientist Robert Floyd, who has also contributed Floyd–Warshall algorithm, which efficiently finds all shortest paths in a graph and Floyd's cycle-finding algorithm for detecting cycles in a sequence. If you remember, we use this algorithm to find the cycles in linked list. Coming back to Floyd's triangle, it is a right angle triangle which consists natural numbers starting from 1 in the first row. It then goes on with two numbers in second row, 3 numbers in 3rd row and so on. Along with other pattern based exercises and Pascal's triangle, Floyd's triangle is also a good programming exercise and often used in programming and training courses to teach how to program to beginners. It's one of the easier program but help you to build code sense and how to use basic programming constructs e.g. loop, operators and functions.
Read more »
Share:

0 commentaires:

Enregistrer un commentaire