-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
31 lines (26 loc) · 827 Bytes
/
Palindrome.java
File metadata and controls
31 lines (26 loc) · 827 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
//To check whether Palindrome or not
import java.util.*;
class Palindrome {
public static void main(String a[]) {
int i, flag = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the string to check whether palindrome or not");
String s = sc.next();
int n = s.length();
char[] a1 = new char[n];
a1 = s.toCharArray();
System.out.println(a1);
for(i = 0; i < n - i; i++) {
if(a1[i] == a1[n - 1 - i]) {
continue;
} else {
flag = 1;
break;
}
}
if (flag == 0)
System.out.println("The string is palindrome");
else
System.out.println("The string is not palindrome");
}
}