Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program (in Java) that implements a method to find the Pentagonal number

ID: 3592922 • Letter: W

Question

Write a program (in Java) that implements a method to find the Pentagonal number of a positive integer. The program prompts the user to input a positive integer and outputs the Pentagonal number of the integer.

* You should Implement a method named findPentagonal that takes an integer number as its formal parameter and

* returns the pentagonal number. A Pentagonal number is defined as follows,

*           N*(3*N – 1) / 2 where N > 0.

*/

Finish this given code:

import java.util.Scanner;

public class Lab6Part3 {

               public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter an integer");

       int x = in.nextInt();

       // invoke the method to find Pentagonal number and output both the integer an its Pentagonal number.

    }

}

Explanation / Answer

Lab6Part3.java

import java.util.Scanner;

public class Lab6Part3 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter an integer");

int x = in.nextInt();

// invoke the method to find Pentagonal number and output both the integer an its Pentagonal number.

System.out.println("Pentagonal number: "+findPentagonal(x));

}

  

public static double findPentagonal(int n) {

return n * (3 * n - 1) / 2;

}

}

Output:

Enter an integer
5
Pentagonal number: 35.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote