write a program in java to find the 3 digit non prime number which is also a palindrome number.
Answers
Answered by
1
Required Answer:-
Question:
- Write a program in Java to find the three digit non prime number which is also a palindrome number.
Solution:
Here comes the solution.
public class JavaBrainly {
public static void main(String[] args) {
System.out.println("Numbers are..");
for(int i=100;i<1000;i++) {
if(check(i))
System.out.println(i);
}
}
static boolean check(int n) {
int c=0, m=n, s=0;
for(int i=1;i<=n;i++) {
if(n%i==0)
c++;
}
while(n!=0) {
s=s*10+n%10;
n/=10;
}
return (c!=2 && s==m);
}
}
Explanation:
- The check() function checks if a number is a non prime palindrome number or not. If true, then this function returns true else false. The same function is called in main() inside the loop. If the function returns true, then the non prime palindrome number is displayed.
See the attachment for output.
Attachments:
Similar questions