-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrime-Word.java
152 lines (149 loc) · 4.43 KB
/
Prime-Word.java
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import java.util.Scanner;
public class Hello
{
public static void main(String[]args)
{
int t = 0;
boolean [] flag;
flag = new boolean [100000];
Scanner input = new Scanner(System.in);
for(int i = 0; i <= 1000; i++)
{
flag[i] = true;
}
for(int i = 2; i <= Math.sqrt(1000); i++)
{
if(flag[i])
{
for(int j = i; j*i <= 10000; j++)
{
flag[i*j] = false;
}
}
}
String str;
while(input.hasNext())
{
int Sum = 0;
str = input.nextLine();
for(int i = 0; i < str.length(); i++)
{
char ch = str.charAt(i);
if(ch == 'a')
Sum += 1;
else if(ch == 'b')
Sum+=2;
else if(ch == 'c')
Sum += 3;
else if(ch == 'd')
Sum += 4;
else if(ch == 'e')
Sum += 5;
else if(ch == 'f')
Sum +=6;
else if(ch == 'g')
Sum += 7;
else if(ch == 'h')
Sum += 8;
else if(ch == 'i')
Sum += 9;
else if(ch == 'j')
Sum += 10;
else if(ch == 'k')
Sum += 11;
else if(ch == 'l')
Sum += 12;
else if(ch == 'm')
Sum += 13;
else if(ch == 'n')
Sum += 14;
else if(ch == 'o')
Sum += 15;
else if(ch == 'p')
Sum += 16;
else if(ch == 'q')
Sum += 17;
else if(ch == 'r')
Sum += 18;
else if(ch == 's')
Sum += 19;
else if(ch == 't')
Sum += 20;
else if(ch == 'u')
Sum += 21;
else if(ch == 'v')
Sum += 22;
else if(ch == 'w')
Sum += 23;
else if(ch == 'x')
Sum += 24;
else if(ch == 'y')
Sum += 25;
else if(ch == 'z')
Sum += 26;
//Capital letter
else if(ch == 'A')
Sum += 27;
else if(ch == 'B')
Sum+=28;
else if(ch == 'C')
Sum += 29;
else if(ch == 'D')
Sum += 30;
else if(ch == 'E')
Sum += 31;
else if(ch == 'F')
Sum += 32;
else if(ch == 'G')
Sum += 33;
else if(ch == 'H')
Sum += 34;
else if(ch == 'I')
Sum += 35;
else if(ch == 'J')
Sum += 36;
else if(ch == 'K')
Sum += 37;
else if(ch == 'L')
Sum += 38;
else if(ch == 'M')
Sum += 39;
else if(ch == 'N')
Sum += 40;
else if(ch == 'O')
Sum += 41;
else if(ch == 'P')
Sum += 42;
else if(ch == 'Q')
Sum += 43;
else if(ch == 'R')
Sum += 44;
else if(ch == 'S')
Sum += 45;
else if(ch == 'T')
Sum += 46;
else if(ch == 'U')
Sum += 47;
else if(ch == 'V')
Sum += 48;
else if(ch == 'W')
Sum += 49;
else if(ch == 'X')
Sum += 50;
else if(ch == 'Y')
Sum += 51;
else if(ch == 'Z')
Sum += 52;
}
str = "";
if(flag[Sum] == true)
{
System.out.printf("It is a prime word.\n");
}
else if(!flag[Sum])
{
System.out.printf("It is not a prime word.\n");
}
}
}
}