Computer Science, asked by mdey99394, 7 months ago

Write a program in java to accept 20 numbers in a single-dimensional array and print all the palindrome numbers which are prime.

Answers

Answered by anindyaadhikari13
6

Answer:

import java.util.*;

class Program

{

static boolean isTrue(int n)

{

int num = n;

int sum = 0;

boolean palindrome=true, prime=true;

while (n!=0)

{

int r = n%10;

s=s*10+r;

n=n/10;

}

palindrome=(num==sum)? true:false;

int c=0;

for(int i=1;i<=num;i++)

{

if(num%i==0)

c++;

}

prime=(c==2)? true:false;

if(palindrome==true&&prime=true)

return true;

else

return false;

}

static void main()

{

Scanner sc = new Scanner(System.in);

System.out.println("Enter 20 elements for the array.. ");

int a[] = new int[20];

for(int i=0;i<20;i++)

{

a[i] = sc.nextInt() ;

}

//Now, print the no.

for(int j=0;j<20;j++)

{

if(isTrue(a[i]))

System.out.print(a[i] + " ") ;

}

}

}

Explanation:

Hope it helps you..Please mark this answer as the brainliest.

10 thanks + follow = inbox ✌✌

Similar questions