Hi .. Provably I'm setting this up the wrong way in Netbeans.. I open a new projetc and use the default main...then open a new empty java file and type my code , when I run this it runs fine but it doesn't ask for input !

import java.io.*;
public class Palindrome
{
     static boolean CheckPalindrome(String s, int leftSide, int rightSide)
     {
          if (rightSide <= leftSide)
               return true;
          else if (s.charAt(leftSide) != s.charAt(rightSide))
               return false; 
          else
               return CheckPalindrome(s,leftSide+1,rightSide-1);

     }
public static void main(String[] args) throws IOException
     {

          String str;
          int n;          
  
          InputStreamReader inStream = new InputStreamReader( System.in );
          BufferedReader stdin = new BufferedReader( inStream );
          
          System.out.print("Please enter any string: ");
          str = stdin.readLine(); 
  
          int lastPosition = str.length()-1; 
          boolean result = CheckPalindrome(str , 0, lastPosition);
  
          if (result) 
            System.out.println("The string \""+str+"\" is a palindrome "); 
          else          
            System.out.println("The string \""+str+"\" is not a palindrome "); 

     }

}

Does this print:

System.out.print("Please enter any string: ");

It should be printed at the bottom of the screen. Enter input there.

The code seems fine. If you run it from command prompt you should be fine.

Hi .. Provably I'm setting this up the wrong way in Netbeans.. I open a new projetc and use the default main...then open a new empty java file and type my code , when I run this it runs fine but it doesn't ask for input !

import java.io.*;
public class Palindrome
{
     static boolean CheckPalindrome(String s, int leftSide, int rightSide)
     {
          if (rightSide <= leftSide)
               return true;
          else if (s.charAt(leftSide) != s.charAt(rightSide))
               return false; 
          else
               return CheckPalindrome(s,leftSide+1,rightSide-1);

     }
public static void main(String[] args) throws IOException
     {

          String str;
          int n;          
  
          InputStreamReader inStream = new InputStreamReader( System.in );
          BufferedReader stdin = new BufferedReader( inStream );
          
          System.out.print("Please enter any string: ");
          str = stdin.readLine(); 
  
          int lastPosition = str.length()-1; 
          boolean result = CheckPalindrome(str , 0, lastPosition);
  
          if (result) 
            System.out.println("The string \""+str+"\" is a palindrome "); 
          else          
            System.out.println("The string \""+str+"\" is not a palindrome "); 

     }

}

Okay it works but how do I implement a method for example the regexp based method so it would skip blank spaces and punctuations(, . ? ;)?

If you want them completely removed why don't you try the replaceAll method of the String class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.