//This Java program accepts a number 'n' from the user.

//This program then finds the next smallest integer 'm' ≥'n' such

//that 'm' is a prime number and 'm' is a palindrome.

//Palindrome : An integer is said to be a palindrome if it is equal

//to its reverse. Eg 10201 is a palindrome.

//Sample Input : 45

//Sample Output : 101

import java.util.*;

class primePalindrome

{

public static void main()

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number");

int n=sc.nextInt();

int i,j,k,temp,n2=0,l=0;

for(i=n;l==0;i++)

{

k=0;

n2=0;

for(j=2;j<i;j++)

{

if(i%j==0)

{

k=1;

break;

}

}

if(k==0)

{

temp=i;

while(temp>0)

{

n2=(n2*10)+(temp%10);

temp=temp/10;

}

if(n2==i)

{

System.out.println("The next prime and palindrome number is "+i);

break;

}

}

}

}

}

//Author : Mayank Rajoria

//This program then finds the next smallest integer 'm' ≥'n' such

//that 'm' is a prime number and 'm' is a palindrome.

//Palindrome : An integer is said to be a palindrome if it is equal

//to its reverse. Eg 10201 is a palindrome.

//Sample Input : 45

//Sample Output : 101

import java.util.*;

class primePalindrome

{

public static void main()

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number");

int n=sc.nextInt();

int i,j,k,temp,n2=0,l=0;

for(i=n;l==0;i++)

{

k=0;

n2=0;

for(j=2;j<i;j++)

{

if(i%j==0)

{

k=1;

break;

}

}

if(k==0)

{

temp=i;

while(temp>0)

{

n2=(n2*10)+(temp%10);

temp=temp/10;

}

if(n2==i)

{

System.out.println("The next prime and palindrome number is "+i);

break;

}

}

}

}

}

//Author : Mayank Rajoria

## No comments:

## Post a Comment