In the above Java program to display the first 50 pentagonal numbers, we first need to understand what is pentagon?
A pentagonal number is a figurative number that extends the concept of triangular and square numbers to the pentagon, but, unlike the first two, the patterns involved in the construction of pentagonal numbers are not rotation-ally symmetrical.
import java.util.Scanner;
public class pentagon {
public static void main(String[] args) {
int count = 1;
for(int i = 1; i <= 50; i++){
System.out.printf("%-6d",get_Pentagonal_Number(i));
if(count % 10 == 0) System.out.println();
count++;
}
}
public static int get_Pentagonal_Number(int i) {
return (i * (3 * i - 1))/2;
}
}
Sample Output: 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 1247 1335 1426 1520 1617 1717 1820 1926 2035 2147 2262 2380 2501 2625 2752 2882 3015 3151 3290 3432 3577 3725