36) Write a program to input a number and
check whether it is Mersenne Number or
not?(a number is said to be Mersenne number if it is one less than a power of
2, ex- 7 is a Mersenne number 8-1= 7 is the power of two 23)
import java.util.*;
public class Mersenne_number
{
public static void main(String args[ ])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number");
int a = sc.nextInt();
double p = a+1;
while(p>1.0)
{
p=p/2.0;
}
if(p==0)
{
System.out.println("Entered number is a MERSENNE number");
}
else
{
System.out.println("Entered number is not a MERSENNE number");
}
}
}
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal