Monday, June 8, 2020

Java Program On Mersenne number


What is Mersenne number? A number which can be represented in the form of 2^n-1 is a Mersenne number.

For example 127 is a Mersenne number as 2^7-1 equals to 127


import java.util.*;
class Mersenne
{
int i=1,n;
Scanner sc=new Scanner(System.in);
void show()
{
System.out.print(“Enter the number:”);
n=sc.nextInt();
for(;;)
{
If(n==Math.pow(2,i)-1)
{
 System.out.print(“Mersenne Number.”);
break;
}
else if(Math.pow(2,i)-1>n)
{
System.out.print(“Not Mersenne Number.”);
break
}
i++;
}
}
public static void main(String args[])
{
 Mersenne ob=new Mersenne ();
ob.show();
}
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner