PROGRAM 3 : PRIME PALINDROME - ENTER LOWER LIMIT AND UPPER LIMIT AND FIND ALL PRIME PALINDROME NUMBERS IN THAT PARTICULAR RANGE.
(Prime palindrome is number which is prime as well as palindrome in nature.
Example : 11 , 111 )
PROGRAM:
import java.util.Scanner;
public class primepalindrome
{
public static void main(String args[])
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter the upper and lower limit:");
int x = sc.nextInt();
int y = sc.nextInt();
int i;
System.out.println("All prime palindrome numbers:");
for(i=x ; i<=y ; i++)
{
if(isprime(i)== true)
{ if(ispalin(i)== true)
System.out.println(i);
}
}
}
public static boolean isprime(int i)
{ int f = 0;
for(int j = 2 ; j<i ; j++)
{
if(i%j==0)
f++;
}
if(f==0)
return(true);
else
return(false);
}
public static boolean ispalin(int i)
{
int dig;
int ans = 0;
int num = i;
while(num>0)
{
dig = num%10;
ans+= (ans*10)+dig;
num = num/10;
}
if(num==i)
return(true);
else
return (false);
}
}
(Prime palindrome is number which is prime as well as palindrome in nature.
Example : 11 , 111 )
PROGRAM:
import java.util.Scanner;
public class primepalindrome
{
public static void main(String args[])
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter the upper and lower limit:");
int x = sc.nextInt();
int y = sc.nextInt();
int i;
System.out.println("All prime palindrome numbers:");
for(i=x ; i<=y ; i++)
{
if(isprime(i)== true)
{ if(ispalin(i)== true)
System.out.println(i);
}
}
}
public static boolean isprime(int i)
{ int f = 0;
for(int j = 2 ; j<i ; j++)
{
if(i%j==0)
f++;
}
if(f==0)
return(true);
else
return(false);
}
public static boolean ispalin(int i)
{
int dig;
int ans = 0;
int num = i;
while(num>0)
{
dig = num%10;
ans+= (ans*10)+dig;
num = num/10;
}
if(num==i)
return(true);
else
return (false);
}
}
No comments:
Post a Comment