0

This is a class for a bigger project. I programmed it sepratly so that i know it will work when i include it in the project. This is a Palindrome project. SO i want to know if the a word is a palindrome or not. I get the program to reverse the String, but even when the two string are equal to each other it still test as false. Please Help!

import java.util.*;
public class Palindrome_Idriss
{
	public static void main(String[] args)
	{
		boolean result;
		String test = "aba";
		
		StringBuffer reverser = new StringBuffer(test.substring(test.length() - 1, test.length()));
		
		for(int counter = test.length() - 2;  counter >= 0; counter--)
		{
			reverser = reverser.append(test.substring(counter, counter + 1));
		}
		 reverser.toString();
		
		if (reverser.equals(test))
			result = true;
		
		else{
			result = false;}
		
		System.out.println(result);
		System.out.println(test);
		System.out.println(reverser);
	}
}
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by JamesCherrill
Featured Replies
  • reverser.toString(); This line creates a String and returns it, but you do nothing with the returned value. It doesn't change reverser in any way. Read More

1

reverser.toString();
This line creates a String and returns it, but you do nothing with the returned value. It doesn't change reverser in any way.

0

reverser.toString();
This line creates a String and returns it, but you do nothing with the returned value. It doesn't change reverser in any way.

Oh so I should make a veraible that would equal reverser.toString().
example

x = reverser.toString
0

reverser.toString();
This line creates a String and returns it, but you do nothing with the returned value. It doesn't change reverser in any way.

Yeah that worked thank you

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.