Programming Examples

Java program to generate all 2 digit twisted prime number


Write 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.

Solution

class TwistedPrime
{
	public static void main(String ar[])
	{
		int i,j,r,c1,c2,d;
		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+“ ”);
		}
	}
}
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad