Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Palindrome problem

807591Mar 10 2008 — edited Mar 11 2008
hello. can anyone help me? this is kind of a class project, and I'm stuck. here's my program
import java.io.*;

public class lab16B
{
	public static void main (String args[]) throws IOException
	{
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		System.out.print("Enter a string ===> ");
		Palindrome p = new Palindrome(input.readLine());
		p.displayData();
	}
}

class Palindrome
{
	private String s;
	private boolean palindrome;

	private boolean isPal()
	{
		String s2="";
		int n = s.length()-1;
		for(int k = n;k >= 0;k--)
			s2+=s.charAt(k);
		System.out.print(""+s2);

		if(s.equals(s2))
			return true;
		else
			return false;


	}

	public Palindrome(String s)
	{
		this.s=s;
	}

	public void displayData()
	{
		System.out.print(""+s);
		System.out.print("\n");
		System.out.print(""+palindrome);
	}
}
The problem is that whenever I run it, and whatever the string I input, it keeps giving me "false". please help me
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 8 2008
Added on Mar 10 2008
25 comments
344 views