-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromeString.java
More file actions
58 lines (47 loc) · 985 Bytes
/
Copy pathPalindromeString.java
File metadata and controls
58 lines (47 loc) · 985 Bytes
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
//12. Write a JAVA program to check whether a string is palindrome or not.
import java.util.*;
public class PalindromeString
{
public static void main(String x[])
{
Scanner ab=new Scanner(System.in);
System.out.println("Enter the String ");
String a=ab.nextLine();
char ch[]=a.toCharArray();
char ch1[]=new char[a.length()];
for(int i=0; i<a.length(); i++)
{
ch1[i]=ch[i];
}
int end=a.length()-1;
int mid=a.length()/2;
for(int i=0; i<mid; i++)
{
char temp=ch[i];
ch[i]=ch[end];
ch[end]=temp;
end--;
}
boolean flag=false;
for(int i=0 ;i<a.length(); i++)
{
if(ch[i]==ch1[i])
{
flag=true;
}
else
{
flag=false;
break;
}
}
if(flag)
{
System.out.println("Palindrome ");
}
else
{
System.out.println("Not Palindrome ");
}
}
}