I am trying to do an assignment that requires us to do something with pentagonal numbers. This is my code:
import java.util.Scanner;
public class Pentagonal {
public static void main(String[] args) {
System.out.print("The Pentagonal Numbers: ");
getPentagonalNumber(10);
}
public static int getPentagonalNumber(int n) {
Scanner input = new Scanner(System.in);
System.out.print(
"Enter an integer: ");
long n = input.nextInt();
int n1 = 1;
while (n<=100) {
n = (3*n1*n1 - n1)/2;
System.out.println(n);
n1++;
}
return n;
}
}
I am trying to make the output look like this:
Sample Run 1:
Enter an integer: 2
The pentagonal numbers are: 1 5
Sample Run 2:
Enter an integer: 4
The pentagonal numbers are: 1 5 12 22