Tuesday, June 30, 2020

Write a program to input two integers and check whether it’s Tweens Prime or not? (3,5 two Prime numbers which contain difference between two Primes is 2)

38)  Write a program to input two integers and check whether it’s Twins Prime or not? (3,5 two   Prime numbers which contain difference between two Primes is 2)

import java.util.*;

public class Tweens_prime

{

    public static void main(String args[ ])

    {

        Scanner sc = new Scanner (System.in);

        System.out.println("Enter two numbers");

        int a = sc.nextInt();

        int b = sc.nextInt();

        int co = 0;

        int c = 0;

        for(int i=1;i<=a;i++)

        {

            if(a%i==0)

            c++;

        }

        for(int i=1;i<=b;i++)

        {

            if(b%i==0)

            co++;

        }

        if(co==2&&c==2&&(a-b==2||a-b==-2))

        {

            System.out.println("Entered numbers are TWEENS PRIME ");

        }

        else

        {

            System.out.println("Entered numbers are not TWEENS PRIME ");

        }

    }

}

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

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

Write a program to input two numbers and check whether these are Co-Prime or not? (12=1, 2, 3, 4, 6, 12, 25=1, 5, 25 both have one common factor is 1, so it is Co-Prime number.)

35)  Write a program to input two numbers and check whether these are Co-Prime or not?  (12=1, 2, 3, 4, 6, 12,    25=1, 5, 25 both have one common factor is 1, so it is Co-Prime number.)

import java.util.*;
public class COprime_number
{
     public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter two numbers");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = 0;
        for(int i=1;i<=Math.min(a,b)-1;i++)
        {
            if(a%i==0&&b%i==0)
            c++;
        }
        if(c==1)
        {
            System.out.println("Entered numbers are CO-PRIME number");
        }
        else
        {
             System.out.println("Entered numbers are not CO-PRIME number");
        }
    }
}

Write a program to input a number and check whether it is Composite Number or not?(Num is not Prime, called Composite)

34)  Write a program to input a number and check whether it is Composite Number or not?(Num is not Prime, called Composite)

import java.util.*;
public class Composite_number
{
     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++;
        }
        if(c!=2)
        {
            System.out.println("Entered number is a COMPOSITE number");
        }
        else
        {
             System.out.println("Entered number is not a COMPOSITE number");
        }
    }
}

Write a program to input a number and check whether it is Prime Number or not? (Number divided by 1 or itself)

33)  Write a program to input a number and check whether it is Prime Number or not?   (Number divided by 1 or itself)

import java.util.*;
public class Prime_number
{
    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++;
        }
        if(c==2)
        {
            System.out.println("Entered number is a PRIME number");
        }
        else
        {
             System.out.println("Entered number is not a PRIME number");
        }
    }
}

Write a program to input a number and check whether it is Deficient Number or not?(8=1+2+4=7, (sum)<(num))

 32)  Write a program to input a number and check whether it is Deficient Number or not?       (8=1+2+4=7, sum<number)

import java.util.*;
public class Deficient_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int s = 0;
        for(int i=1;i<a;i++)
        {
            if(a%i==0)
            s=s+i;
        }
        if(s<a)
        {
            System.out.println("Entered number is a DEFICIENT number");
        }
        else
        {
            System.out.println("Entered number is not a DEFICIENT number");
        }
    }
}

 jhvghvgk ;nkjn ,nkjhj