Monday, June 29, 2020

Write a program to input a number and check whether it is Mersenne Prime Number or not? (A number is said to be Mersenne prime number if it is Mersenne and Prime both.)

37)   Write a program to input a number and check whether it is Mersenne Prime Number or not? (A number is said to be   Mersenne prime number if it is Mersenne and Prime both.)

import java.util.*;
public class Mersenne_prime_6
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int c = 0;
        for(int i=1;i<=a;i++)
        {
            if(a%i==0)
            c++;
        }
        double p = a+1;
        while(p>1.0)
        {
            p=p/2.0;
        }
        if(p==1&&c==2)
        {
            System.out.println("Entered number is a MERSENNE PRIME");
        }
        else
        {
            System.out.println("Entered number is not a MERSENNE PRIME");
        }
    }
}

No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj