-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHowlingPrime.java
More file actions
79 lines (79 loc) · 1.91 KB
/
HowlingPrime.java
File metadata and controls
79 lines (79 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*A howling prime is a prime number if the sum of its digits is also a prime number.
Input:113
Output: true (113 is a prime number, 1+1+3=5 is also a prime number)
*/
import Aaryan.X;
import java.util.*;
public class HowlingPrime
{
public static void main(String[] args)
{
int dig,sum=0;
Scanner in=new Scanner(System.in);
System.out.println("1.Single \n2.Range");
int cho=in.nextInt();
switch(cho)
{
case 1:System.out.println("Enter the Number");
int num=in.nextInt();
boolean res=X.isPrime(num);//This method is in my X class
int len=String.valueOf(num).length();//find the length of the int
int temp=num;
if(res==true)
{
while(temp>0)
{
dig=temp%10;
sum+=dig;
temp=temp/10;
}
boolean res2=X.isPrime(sum);
if(res2==true)
{
System.out.println(num+" is a Prime Number & Howling Prime Number");
}
else
{
System.out.println(num+" is a Prime Number but not a Howling Prime Number");
}
}
else
{
System.out.println(num+" is not a Prime Number");
}
break;
case 2:System.out.println("Enter the Starting number");
int num3=in.nextInt();
System.out.println("Enter the Ending number");
int num4=in.nextInt();
for(int i=num3;i<=num4;i++)
{
res=X.isPrime(i);
temp=i;
if(res==true)
{
while(temp>0)
{
dig=temp%10;
sum+=dig;
temp=temp/10;
}
boolean res2=X.isPrime(sum);
if(res2==true)
{
System.out.println(i+" is a Prime Number & Howling Prime Number");
}
else
{
System.out.println(i+" is a Prime Number but not a Howling Prime Number");
}
}
else
{
System.out.println(i+" is not a Prime Number");
}
}
break;
}
}
}