Twisted prime in java || for loop || Java programs || Java


In this, we are going to see the program of twisted prime numbers in Java.

A program to generate all 2 digit twisted prime number. 
Twisted prime number is a number which is prime and its 
reverse is also prime. Example 13 and 31.


class Twisted 
{
    public static void main(String[] args) 
    {
        int i, j, r, c1, c2, d;
        System.out.println("\n");
        for (i = 10; i <= 99; i++) 
        {
            c1 = 0;
            for (j = 1; j <= i; j++) 
            {
                if (i % j == 0)
                {
                    c1++;
                }
            }
            r = 0;
            for (j = i; j > 0; j /= 10) 
            {
                d = j % 10;
                r = r * 10 + d;
            }
            c2 = 0;
            for (j = 1; j <= r; j++) 
            {
                if (r % j == 0)
                {
                    c2++;
                }
            }
            if (c1 == 2 && c2 == 2)
            {
                System.out.println(i + " ");
            }
        }
    }
}

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post