Java程序显示Floyd三角形
Floyd的三角形是一个由自然数构成的流行的直角三角形数组。其名称来自于其创始人罗伯特·W·弗洛伊德,他是一位著名的计算机科学家。三角形的顶部是数字1,然后在每一行向下移动时,每个后续数字递增1。
在本文中,我们将看到如何使用Java程序来显示Floyd的三角形。
但在进行Java实现之前,让我们更深入地了解一下弗洛伊德三角形。
第一行只包含一个数字,即1本身,每个后续行比前一行多一个数字。三角形有n行,其中n可以是任何正整数。
The total number of values in the triangle will be the sum of the 1st n natural numbers which is calculated using the formula S = n/2 * (2a + (n-1) d) where S is the sum of the series, n is the number of terms in the series, a is the first term in the series, d is the common difference between the terms.
However, in a Floyd’s triangle, the 1st term is always 1 and the common difference is 1 so we can simplify this formula to:
S= n/2 * (2 + n – 1) = n/2 * (n+1)登录后复制