-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
32 lines (30 loc) · 969 Bytes
/
Copy pathPalindrome.java
File metadata and controls
32 lines (30 loc) · 969 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
// Palindrome
package codingbat;
import java.util.Scanner;
public class Palindrome {
public static void checkPalindrome(String orgStr){
String revStr = orgStr;
String temp = "";
int len = orgStr.length();
if(len == 1 || len == 0){
}
else{
for(int i = len-1; i >= 0; i-- ){
temp = temp + orgStr.charAt(i);
}
revStr = temp;
if(revStr.equals(orgStr)){
System.out.println("The string is a Palindrome!");
}
else{
System.out.println("The string is NOT a Palindrome!");
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the string to check if it is a palindrome!");
String orgStr = sc.nextLine();
checkPalindrome(orgStr);
}
}