Write [login to view URL] from page 212 Ninth edition.
" 5.1M (Math: pentagonal numbers) A pentagonal number is defined as n(3n–1)/2 for n=1,2, . . ., and so on.
Therefore, 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)"
Pentagonal numbers illustration and general equation....
Which is Pn = ( 3 * n2 - n )/2
Note for n =1 we have one vertex point
for n = 2 we share vertex points for n=1 and add four more points this gives a pentagonal P2= 5 points
For P3, we share vertex points of P2 and add 7 more points this gives P3 = 12 points
For P4 we add 10 more points + 12 from P3 gives a P4 = 22.
You will read a single integer from standard input and print out the the first n pentagonal numbers, where n was integer just read. All numbers will be printed space then number, last pentagonal number is new line terminated.
Sample Run 1 (Input 2):
Enter an integer: 2
The pentagonal numbers are: 1 5
Sample Run 2 (User input's 4):
Enter an integer: 4
The pentagonal numbers are: 1 5 12 22
Sample Run 3 (NetBeans output window user inputs 7)
Enter an integer: 7
The pentagonal numbers are: 1 5 12 22 35 51 70
BUILD SUCCESSFUL (total time: 7 seconds)
Hint the method getPentagonalNumber( int n ), is singular, but you can write your method to kick out and array 1..n.
For [login to view URL] with input 2, you will need to output:space1space5newline, so we print a space then a number.
The only catch the last number ends in newline not space.
Lets look at another example, you want to read in n and print out the squares of 1 up to n^2, last one is newline terminated.
For example, input n=3; Output: "The square numbers are: 1 4 9\n" - this Simple loop will work....
[login to view URL]( "The square numbers are: " );
for( int i = 1; i <= n ; ++i ) [login to view URL]( i*i + ( i-1<n ? " " : \n" ) );
48 freelancers are bidding on average $21 for this job
I have been working as a software developer for more than one and half year and having good knowledge of algorithms and data structures and good at problem solving
i can make it in less than one hour. I read thr implementation steps and i can make it fast. I work with IntelliJ to program Java apps. If you are interested in my offer then leave me a message on chat