Answer:
public static int getPentagonalNumber( int n ){
//initialize the variable
int NthpentagonalNumber;
// use formula
NthpentagonalNumber = n*((3*n)-1)/2;
//return the result
return NthpentagonalNumber;
}
Step-by-step explanation:
Create the function with return type int. it means, the function returns the integer value to the calling function.
In the function, we declare the one parameter with an integer type. so, it takes the value from the calling function.
then, initialize the variable for storing the output.
the formula for calculating the pentagonal number is:
the value is passed by the user and the function capture the value in the parameter and then use the formula to store the output the variable.
and finally, return the output.