Computer Science, asked by INDIAN04, 11 months ago

java program using scanner to print prime palindrome no.s between 10 to 1000​

Answers

Answered by rakeshchennupati143
50

Program:

public class Main{

     public static void main(String[] args) {

           for(int i = 10 ; i < 1000 ; i++){

                 int reversed = 0;

                 int num = i;

                 while(num != 0) {

                       int digit = num % 10;

                       reversed = reversed * 10 + digit;

                       num /= 10;

                 }if(i == reversed){

                       boolean flag = false;

                       for(int j = 2; j <= i/2; ++j){

                             if(i % j == 0){

                                   flag = true;

                                   break;

                             }

                       }if(!flag){

                             System.out.print(i+",");

                       }

                 }

           }

     }

}

Output:

11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929,

Explanation:

  • first i took a loop of numbers from 10 to 1000
  • then i took each number and checked if it is palindrome or not
  • if true then again i checked if that palindrome number is prime or not using simple prime checking method
  • if it is also true then at last the number will be printed
  • if not then loop iterates and moves on to next number

----Hope you understood my program, mark brainliest if you like my program, In future if you have any doubts in programming or coding feel free to approach me and ask about them, i'll try to solve or in most of the cases i'll answer to your doubts or problems    :)

Answered by amannishad0512p5zxh6
34

Prime Palindrome

A number that is prime(factor only 1 and itself the number) and Palindrome(reverse of number is same as number)

Example :-11 ,101 are prime Palindrome and many more.

class prime_palindrome

{

public static void main (String args[ ] )

{

int i, count,j,a,rev,h=0;

System.out.println("Prime Palindrome numbers between 10 to 1000");

for(i=10;i<=1000;i++)

{

count=0; rev=0;

h=i; // to make a copy of i

for(j=1;j<=i;j++) // to check for prime number

{

if(i%j==0)

count++;

}

while(h!=0)

{

a=h%10;

rev+=rev*10+a;

h=h/10;

}

if(rev==i && count==2)

System.out.print(i+" ");

}

}

}

Hope it will help.

There is no need of Scanner class in it.


rakeshchennupati143: see your program once all confusing to read, such a lunatic person XD
amannishad0512p5zxh6: bro,its okk
amannishad0512p5zxh6: Apna apna style hai
rakeshchennupati143: in every programming languages if tab is required you have to give tag or 6 spaces to differentiate the functions and their statements i'm just telling you to add spaces to your program from next time onward's ;)
amannishad0512p5zxh6: No,not necessary
rakeshchennupati143: why without spaces the program will be confusing for the reader
Similar questions