-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpalword.java
53 lines (37 loc) · 1.03 KB
/
palword.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
import java.io.*;
public class palword
{
public static void main()throws IOException{
int s =0;String s1=" ";String str2=" ";String str1=" ";String str3 = " ";String st4=" ";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter a string");
String str = br.readLine();
str1=str+" ";int v=0;
int b = str1.length();
char ch;char ch1;
for(int i=0;i<b;i++){
ch = str1.charAt(i);
if(ch!=' '){
str2=str2+ch;
}
else {
str3 =str2.trim();
int c = str3.length();
int j=0;
for(j=c-1;j>=0;j--){
ch1 = str3.charAt(j);
s1=s1+ch1;
st4 = s1.trim();
}
if(str3.compareTo (st4)==0){
v=v+1;
System.out.println("palindrome words are:"+st4);
}
s1="";
st4="";
str2="";
}
}
System.out.println("frequency"+v);
}
}