2. A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, ..., etc.. Therefo the first few numbers are 1, 5, 12, 22, . . . . Write a method with the following header that returns a pentagonal number: public static int getPentagonalNumber(int n)
2. A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, ..., etc.. Therefo the first few numbers are 1, 5, 12, 22, . . . . Write a method with the following header that returns a pentagonal number: public static int getPentagonalNumber(int n)
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 7E
Related questions
Question

Transcribed Image Text:2. A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, ..., etc.. Therefore,
the first few numbers are 1, 5, 12, 22, ... . Write a method with the following
header that returns a pentagonal number:
%3D
public static int getPentagonalNumber(int n)
For example, getPentagonalNumber(1) returns 1
and getPentagonalNumber(2) returns 5. Write a test program that uses this method
to display the first 100 pentagonal numbers with 10 numbers on each line.
Numbers are separated by exactly one space.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images

Recommended textbooks for you

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr