(Math: pentagonal numbers) java


6-1) (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)

Write a test program  that uses this method  to display the first n pentagonal
numbers with 10 numbers on each line, one space between  each number, and the user entering the integer value  for n.


SAMPLE RUN #1

— Prompts For Keyboard/Console/Standard Input —

Enter an integer  for the n pentagonal numbers you want displayed:


Inputs

— Keyboard/Console/Standard Input stdin —

20 


Outputs 

— Monitor/Console/Standard Output  —

Enter an integer  for the n pentagonal numbers you want displayed:1 5 12 22 35 51 70 92 117 145 
176 210 247 287 330 376 425 477 532 590 


What The Console Looks Like In An Interactive Session:

(Note: this combines standard input with standard output )

>java PentagonalNumbers 
Enter an integer  for the n pentagonal numbers you want displayed: 20 
1 5 12 22 35 51 70 92 117 145 
176 210 247 287 330 376 425 477 532 590 


SAMPLE RUN #2

— Prompts For Keyboard/Console/Standard Input —

Enter an integer  for the n pentagonal numbers you want displayed:


Inputs

— Keyboard/Console/Standard Input stdin —

33 


Outputs 

— Monitor/Console/Standard Output  —

Enter an integer  for the n pentagonal numbers you want displayed:1 5 12 22 35 51 70 92 117 145 
176 210 247 287 330 376 425 477 532 590 
651 715 782 852 925 1001 1080 1162 1247 1335 
1426 1520 1617 


What The Console Looks Like In An Interactive Session:

(Note: this combines standard input with standard output )

>java PentagonalNumbers 
Enter an integer  for the n pentagonal numbers you want displayed: 33 
1 5 12 22 35 51 70 92 117 145 
176 210 247 287 330 376 425 477 532 590 
651 715 782 852 925 1001 1080 1162 1247 1335 
1426 1520 1617 


SAMPLE RUN #3

— Prompts For Keyboard/Console/Standard Input —

Enter an 
integer  for the n pentagonal numbers you want displayed:


Inputs

— Keyboard/Console/Standard Input stdin —

67 


Outputs 

— Monitor/Console/Standard Output  —

Enter an 
integer  for the n pentagonal numbers you want displayed:1 5 12 22 35 51 70 92 117 145 

176 210 247 287 330 376 425 477 532 590 

651 715 782 852 925 1001 1080 1162 1247 1335 

1426 1520 1617 1717 1820 1926 2035 2147 2262 2380 

2501 2625 2752 2882 3015 3151 3290 3432 3577 3725 

3876 4030 4187 4347 4510 4676 4845 5017 5192 5370 

5551 5735 5922 6112 6305 6501 6700 


What The Console Looks Like In An Interactive Session:

(Note: this combines standard input with standard output )

>java PentagonalNumbers 

Enter an 
integer  for the n pentagonal numbers you want displayed:
 67 

1 5 12 22 35 51 70 92 117 145 

176 210 247 287 330 376 425 477 532 590 

651 715 782 852 925 1001 1080 1162 1247 1335 

1426 1520 1617 1717 1820 1926 2035 2147 2262 2380 

2501 2625 2752 2882 3015 3151 3290 3432 3577 3725 

3876 4030 4187 4347 4510 4676 4845 5017 5192 5370 

5551 5735 5922 6112 6305 6501 6700 


SAMPLE RUN #4

— Prompts For Keyboard/Console/Standard Input —

Enter an 
integer  for the n pentagonal numbers you want displayed:


Inputs

— Keyboard/Console/Standard Input stdin —

43 


Outputs 

— Monitor/Console/Standard Output  —

Enter an 
integer  for the n pentagonal numbers you want displayed:1 5 12 22 35 51 70 92 117 145 

176 210 247 287 330 376 425 477 532 590 

651 715 782 852 925 1001 1080 1162 1247 1335 

1426 1520 1617 1717 1820 1926 2035 2147 2262 2380 

2501 2625 2752 


What The Console Looks Like In An Interactive Session:

(Note: this combines standard input with standard output )

>java PentagonalNumbers 

Enter an 
integer  for the n pentagonal numbers you want displayed:
 43 

1 5 12 22 35 51 70 92 117 145 

176 210 247 287 330 376 425 477 532 590 

651 715 782 852 925 1001 1080 1162 1247 1335 

1426 1520 1617 1717 1820 1926 2035 2147 2262 2380 

2501 2625 2752 

compile w NetBeans

"Is this question part of your assignment? We can help"

ORDER NOW