Page 534 - Cs_withBlue_J_C11_Flipbook
P. 534
Program 18 Write a program to input a number and using recursion method check whether the number
is an Emirp Number or not.
An emirp number is a number which is prime backwards and forwards. Example : 13 and 31
are both prime numbers. Thus, 13 is an emirp number.
class name : Emirp
Data Members
int num : to input a number
int rev : stores the reverse of the number n
int flag : is a flag variable
Member Methods
Emirp(int nn) : parameterised constructor to assign num=n
int isprime(int x) : recursive function to check whether the parameter is a
prime number or not
void isEmrip() : calls isprime(int) and checks whether it is a emirp
number or not
1 import java.util.*;
2 class Emirp
3 {
4 int num, rev,f;
5 Emirp(int nn)
6 {
7 num=nn;
8 rev=0;
9 f=2;
10 }
11 int isprime(int x)
12 {
13 if(num==x)
14 return 1;
15 else if (num%x==0 || num==1)
16 return 0;
17 else
18 return isprime(x+1);
19 }
20
21 void isEmirp()
22 {
23 int orgnum,revnum,x;
532532 Touchpad Computer Science-XI

