Computer Science, asked by sj76236, 5 months ago

Write a java program to accept an integer value n and print all the Palprime numbers from 1 to n.

Palprime Number: The number which is both Prime and as well as Palindrome.

Prime Number: The number which has only two factors 1 and the number itself.

Palindrome Number: The number whose reverse is equal to the number itself.​

Answers

Answered by asitpaul2015ap
2

Answer:

class PrimeNumbers

{

public static void main (String[] args)

{

int i =0;

int num =0;

//Empty String

String primeNumbers = "";

for (i = 1; i <= 100; 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 100 are :");

System.out.println(primeNumbers);

}

}

Similar questions