Prime and Palindrome in array in java
import java.io.*;
class learningdesi
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter the elements in an array”);
int n[]=new int[5];
// inputing the elements in array
for(int i=0;i<n.length;i++)
{
n[i]=Integer.parseInt(br.readLine());
}
//new array is created to input the prime and palindrome number
int m[]=new int[5];
int l=1;
// loop for checking the prime number
for(int j=0;j<n.length;j++)
{
int i=n[j];
int sum=0;
int c=0;
for(int k=1;k<i;k++)
{
if(i%k==0)
{
c++;
}
}
// this loop will check the palindrome number
while(i>0)
{
int x= i%10;
sum=sum*10+x;
i=i/10;
}
if(sum==n[j] && c==1)
{
m[l]=n[j];
System.out.println(m[l]);
l++;
}
else
{
c=0;
sum=0;
}
}
}
}