Showing posts with label mersenne number. Show all posts
Showing posts with label mersenne number. Show all posts

Sunday, June 21, 2020

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 2^3)

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");
        }
    }
}

 jhvghvgk ;nkjn ,nkjhj