File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ public class Palindrome {
3+ static boolean isPalindrome (String word ) {
4+ char [] letterArray = word .toCharArray ();
5+ int startingIndex = 0 ;
6+ int lastIndex = letterArray .length - 1 ;
7+ while (lastIndex > startingIndex ) {
8+ if (letterArray [startingIndex ] != letterArray [lastIndex ]) {
9+ return false ;
10+ }
11+ ++startingIndex ;
12+ --lastIndex ;
13+ }
14+ return true ;
15+ }
16+ public static void main (String args []) {
17+ Palindrome palindrome = new Palindrome ();
18+ while (true ) {
19+ System .out .printf ("Enter a word which needs to check whether a palindrome or not: " );
20+ Scanner scan = new Scanner (System .in );
21+ String input = scan .next ();
22+ System .out .printf ("The word '%s' is a palindrome : %s %n" , input , palindrome .isPalindrome (input ));
23+ }
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments