Jump to content

[Java] Palindrome App Won't Work. Help.`

creativename
Go to solution Solved by fizzlesticks,

You initialized reverse to a space, it should be an empty string.

My code is.....

 

class Palindrome
{
   public static void main(String args[])
   {
       String word, reverse = " ";
  EasyReader input = new EasyReader();
  
  System.out.println("Input a word");
  word = input.readWord();
  
  int length = word.length();
 
      for ( int i = length - 1; i >= 0; i-- )
         reverse = reverse + word.charAt(i);
 
      if (word.equals(reverse))
         System.out.println("It is a palindrome.");
      else
         System.out.println("It is not a palidrome.");
 
   }
}
 
 
 
No matter what word I input, I always get back the else SOP. 

CPU: Intel Core i7 2600k | Mootherboard: ASUS P8z68v-Pro | GPU: EVGA GTX780Ti 3GB | RAM: Kingston HyperX Genesis 8GB (4GBx2) 1600mhz | PSU: Corsair AX760 | STORAGE: Samsung 840 Pro 512GB | COOLER: Noctua NH-C14 | CASE: Fractal Design Define R4 Pearl Black | Operating SystemWindows 7 Professional 64-bit |

Link to comment
Share on other sites

Link to post
Share on other sites

You initialized reverse to a space, it should be an empty string.

Thanks. I feel stupid now, I stared at it for like 2 hours wondering what was wrong.

CPU: Intel Core i7 2600k | Mootherboard: ASUS P8z68v-Pro | GPU: EVGA GTX780Ti 3GB | RAM: Kingston HyperX Genesis 8GB (4GBx2) 1600mhz | PSU: Corsair AX760 | STORAGE: Samsung 840 Pro 512GB | COOLER: Noctua NH-C14 | CASE: Fractal Design Define R4 Pearl Black | Operating SystemWindows 7 Professional 64-bit |

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×