Java Saved Program: quiescent-mountain

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


import java.io.*;
import java.util.*;
class twinp
{
    int prime(int n)
    {
        int i,c=0,f=0;
        for(i=1;i<=n;i++)
        {
            if(n%i==0)
            c=c+1;
        }
        if(c==2)
        f=1;
        return(f);
    }
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        int m,p,x,y;
        twinp ob=new twinp();
        System.out.println("enter your first number");
        m=in.nextInt();
        System.out.println("enter your second number");
        p=in.nextInt();
        x=ob.prime(m);
        y=ob.prime(p);
        if((x==1&&y==1)&&(m-p==2||p-m==2))
        System.out.println("the number"+m+"and"+p+"are twin primes");
        else
        System.out.println("the number"+m+"and"+p+"are not twin numbers");
    }
}
        
        
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs