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

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

ID: 3628979 • Letter: P

Question

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.

Explanation / Answer

please rate - thanks

in the future cramster rule 1 question per post not 3 --I'm doing 2

import java.util.*;
public class pentagonal
{public static void main(String [] args)
    {Scanner in=new Scanner(System.in);
    int n;
    System.out.println("The first 100 Pentagonal numbers are ");
    for(n=1;n<=100;n++)
        {System.out.print(getPentagonal(n)+" ");
        if(n%10==0)
              System.out.println();
    }
}
public static int getPentagonal(int n)
{return n*(3*n-1)/2;
}
}

--------------

import java.util.*;
public class Main
{public static void main(String [] args)
    {Scanner in=new Scanner(System.in);
    calculateSeries();
    }

public static void calculateSeries()
{int i;
double sum=0, num;
System.out.println("i m(i)");
for(i=1;i<=20;i++)
    {num=i/(double)(i+1);
    sum+=num;
    System.out.println(i+" "+sum);
    }
}
}