-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
34 lines (26 loc) · 750 Bytes
/
Palindrome.java
File metadata and controls
34 lines (26 loc) · 750 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
package com.sarvesh.javabasics;
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = sc.nextLine();
int start = 0;
int end = str.length() - 1;
boolean isPalindrome = true;
while (start < end) {
if (str.charAt(start) != str.charAt(end)) {
isPalindrome = false;
break;
}
start++;
end--;
}
if (isPalindrome) {
System.out.println("Palindrome");
} else {
System.out.println("Not Palindrome");
}
sc.close();
}
}