Write a program in java to check the number entered by user is palindromic prime.
Palindromic prime are the number which are prime and it's reverse is the same
For example n= 151 it is a prime number
And it's reverse is also same ,i.e, 151.
Answers
Answered by
2
import java
. -------------- util.Scanner;
class PrimeNumbers2
{
public brainly
static
=void main
(String[] args)
{
Scanner scanner = new Scanner
(System.in); int i =0; int num =0
; //Empty String String primeNumbers = "
"; System.out.println("Enter the value of n:");
int n = scanner.nextInt(); scanner.close();
for (i = 1; i <= n; i++) { int counter=0; for
(
num =i; num>=1; num--)
{
if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2)
{
//Appended the Prime number to the String primeNumbers = primeNumbers + i + " ";
}
}
System.out.println
("Prime numbers from 1 to n are :")
; System.out.println(primeNumbers); } }
. -------------- util.Scanner;
class PrimeNumbers2
{
public brainly
static
=void main
(String[] args)
{
Scanner scanner = new Scanner
(System.in); int i =0; int num =0
; //Empty String String primeNumbers = "
"; System.out.println("Enter the value of n:");
int n = scanner.nextInt(); scanner.close();
for (i = 1; i <= n; i++) { int counter=0; for
(
num =i; num>=1; num--)
{
if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2)
{
//Appended the Prime number to the String primeNumbers = primeNumbers + i + " ";
}
}
System.out.println
("Prime numbers from 1 to n are :")
; System.out.println(primeNumbers); } }
Similar questions