wap to print mersenne number (NO. IN THE FOM OF 2 /\-1) read a limit from the user and print all mersenne number until it exceeds the given number also mention the mersenne number which has exceeded the limit.
Answers
Answered by
2
This program prints the series of mersenne numbers till a given number of terms, in JAVA.
PROGRAM -
import java.util.*;
public class MersenneNumberSeries
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter number of terms to be printed.");
int n=ob.nextInt();
System.out.println("The series is-");
for(int i=1;i<=n;i++)
{
int number=(int)Math.pow(2,i)-1;
System.out.print(number+", ");
}
}
}
Similar questions