File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import  java .util .*;
2+ import  java .lang .*;
3+ 
4+ /** 
5+  * Palindrome 
6+  */ 
7+ public  class  Palindrome  {
8+  static  boolean  isPalindrome (String  s ) {
9+ 
10+  // Left and right pointers pointing to the beginning and the end of the string  
11+ 
12+  int  left  = 0 , right  = s .length () - 1 ;
13+  
14+  while  (left  < right ) { 
15+  
16+  // If there is a mismatch  
17+ 
18+  if  (s .charAt (left ) != s .charAt (right )) 
19+  return  false ; 
20+  
21+  // Increment left pointer and decrement right pointer 
22+  left ++; 
23+  right --; 
24+  } 
25+  return  true ; 
26+  }
27+ 
28+  public  static  void  main (String [] args ) {
29+  
30+  Scanner  sc  = new  Scanner (System .in ); 
31+ 
32+  String  str  = sc .nextLine (); //Input a string 
33+  
34+  System .out .println (isPalindrome (str )); // Print whether the input string is palindrome or not 
35+  
36+  }
37+ }
                         You can’t perform that action at this time. 
           
                  
0 commit comments