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);
	}
}

Recommended Answers

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.

Jump to Post

All 4 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.

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

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

OK. Mark this "solved" please.

Be a part of the DaniWeb community

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