forked from tusharjuneja06/simplejavaprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromeCheck.java
More file actions
26 lines (24 loc) · 764 Bytes
/
PalindromeCheck.java
File metadata and controls
26 lines (24 loc) · 764 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
import java.util.Scanner;
class PalindromeCheck{
static boolean isPalindrome(String word){
int len = word.length();
char ch1, ch2;
for(int i=0;i<len;i++){
ch1 = word.charAt(i);
ch2 = word.charAt(len - i -1);
if(Character.toLowerCase(ch1)!=Character.toLowerCase(ch2))
return false;
}
return true;
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.print("Enter a string: ");
String word = scan.nextLine();
scan.close();
if(isPalindrome(word))
System.out.println(word + " is a palindrome.");
else
System.out.println(word + " is not a palindrome.");
}
}