Home / Questions / Part 1: A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, 3, … and so on. So, the first few

Part 1: A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, 3, … and so on. So, the first few

Part 1: A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, 3, … and so on. So, the first few
numbers are 1, 5, 12, 22, … Write the following method that returns a pentagonal number:
public static int getPentagonal Number( int n)
The input (n) is the nth pentagonal number. So, for an input of 2, the method should return 5.
Write a test program that displays the first 100 pentagonal numbers.


Part 2: Write a method that computes the following series:
m(i) = 1/2 + 2/3 + 3/4 + … + i/(i+1)
Write a test program that displays the following table:
i m(i)
1 0.5
2 1.1667

19 16.4023
20 17.3546
Do not worry about having a specific number of decimal places in the output.

Part 3: A prime number is called a Mersenne prime if it can be written in the form of 2p – 1 (2 raised to
the p power – 1) for some positive integer p. Write a program that lists all Mersenne primes with p
31.
Note that an int will hold values between -231 and +231 – 1, so an int variable can be used for this
problem.
You do not have to use methods in this problem, but you will likely find it easier to use stepwise
refinement techniques described in section 5.12 of the text to simplify the problem.

 

Apr 18 2020 Read more Less More

Answer (Solved)

question Subscribe To Get Solution

Recent Questions

Chat Now

Welcome to Live Chat

Welcome to MyCourseHelp Services, World's leading Academic solutions provider with Millions of Happy Students.

Please fill in the form