-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPalindrome.java
49 lines (30 loc) · 919 Bytes
/
Palindrome.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
/**************************************
* experiment no : 1
* Author : Ashly Rose Antony
* Date : 29/11/2021
* Version : 1.0
* *********************************/
package execises;
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
int flag =0;
System.out.print("Enter a string: ");
Scanner sc = new Scanner(System. in);
String input = sc.next();
System.out.println("The entered string is "+input);
int length=input.length();
for(int i=0;i<length;i++) {
if(input.charAt(i)!= input.charAt(length-i-1)) {
flag=-1;
break;
}
}
if (flag == -1) {
System.out.print("This is not a palindrome");
}
else {
System.out.print("This is a palindrome");
}
}
}