PalPrime Number in JAVA
Palindromic Prime Number in JAVA
If a number is simultaneously palindromic and prime then it is said to be a PalPrime Number.
Example: Number 313, 353 etc are PalPrime number.
Example: Number 313, 353 etc are PalPrime number.
Algorithm and Program below :-
ALGORITHM :-
- Get the number to check for PalPrime Number
- Hold the number in temporary variable
- Using loop find if it is prime or not.
- Check if the number is Palindrome or not.
- If the number is both prime and palindrome print "PalPrime Number"
- If not print "Not a PalPrime Number"
PROGRAM below :-
import java.io.*;
import java.util.*;
class PalPrime
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int n,p,rev,s=0,i,c=0;
System.out.println("Enter No.");
n= in.nextInt(); // Input number from user
p=n; // store the entered number in "p" variable
for(i=1;i<=p;i++)
{
if(p%i==0)
{
c++;
}
}
while(n>0)
{
rev=n%10; // extract last digit of the number
s=s*10+rev; // store the digit last digit
n=n/10; // extract all digit except the last
}
if(p==s&&c==2) // comparing with original number
{
System.out.println("Number is PalPrime : "+p);
}
else
{
System.out.println("Number is not PalPrime : "+p);
}
} // end of main method
} // end of class
import java.io.*;
import java.util.*;
class PalPrime
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int n,p,rev,s=0,i,c=0;
System.out.println("Enter No.");
n= in.nextInt(); // Input number from user
p=n; // store the entered number in "p" variable
for(i=1;i<=p;i++)
{
if(p%i==0)
{
c++;
}
}
while(n>0)
{
rev=n%10; // extract last digit of the number
s=s*10+rev; // store the digit last digit
n=n/10; // extract all digit except the last
}
if(p==s&&c==2) // comparing with original number
{
System.out.println("Number is PalPrime : "+p);
}
else
{
System.out.println("Number is not PalPrime : "+p);
}
} // end of main method
} // end of class
Thankyou so much sir
ReplyDeleteIt was my pleasure to help you
DeleteKeep Learning :)
It was very much helpful.... thnk u....
ReplyDeleteIt was my pleasure to help you
DeleteKeep Learning :)
Not helpful
ReplyDeleteVery much confusing
Hi! I'm sorry to hear that it is not helpful for you. Please checkout this video (link : https://youtu.be/iRL0v805om8). If you still find this not helpful than let me know.
DeleteIt was really helpful but please also write the output for the programs (it applies for this one also) .
DeleteOkay! Sure I'll update the posts in few days. Thanks for your comment :)
DeleteThis is the Worst website i have ever seen !! Not at all helpful....
ReplyDeleteHi! I'm sorry to hear that it is not helpful for you. Can you please elaborate why you feel that it is not helpful?
DeleteIt was very helpful to me sir๐๐๐
ReplyDeleteThanks for your comment. You can Follow me on Instagram (@bluejcode).
DeleteKeep Learning :)
It is very helpful but only output or dry run is needed
DeleteEven I need to the output and dryrun
DeletePlease contact me on Instagram(@bluejcode) if possible. I will surely help you out.
DeleteVery helpful ๐๐๐
ReplyDeleteThanks, Do checkout my Youtube Channel (https://www.youtube.com/bluejcode/)
Deletenice program
ReplyDeleteThank you. Keep Learning :)
DeleteSatyam U r from IIES..
ReplyDeleteYes I am from IIES. Please contact me on Instagram(@bluejcode).
DeleteNice program .
ReplyDeleteThanks, You can also follow me on Instagram, Twitter (@bluejcode)
Deletecan you write the program in c.
ReplyDeleteThank you! It was good.
ReplyDeleteMost Welcome :)
DeleteReally ****ing awesome. This is exactly how I wanted. My school teaches in this way only.
ReplyDelete