1.

Write a class with the following method: 1. boolean prime(int n) which returns true if n is prime and false if n is not prime...2.void call() to display all two digit twin prime numbers​

Answer»

public class Prime {public static boolean prime(int n)    {int c=0;        for (int i=1;i<=n;i++)        {if (n%i==0)            c=c+1;        }        if (c==2)        return true;        else        return false;    }    public VOID call()    {int a=10,b=99,c=11,d;        System.out.println("2 digit Twin prime NUMBERS are ");        for (;a<=b;a++)        {if (prime(a))            {d=c;                c=a;                if ((c-d)==2)                System.out.println(d+","+c);            }        }    }    public static void main(STRING ARGS[])    {Prime ob=new Prime();        ob.call();    } }Explanation:



Discussion

No Comment Found