Thanks to Zhen Zhen for a better solution to my program.
It runs, but doesn't print the right info. There is something else not right about the program. What else could I do to fix this?
import java.util.*;
import java.io.*;
public class PalindromeTester
{
public static void main (String [] args)
{
Scanner scan=new Scanner (System.in);
String input;
System.out.print ("Enter a text");
input=scan.next();
Palindrome obj=new Palindrome (input);
boolean isP=obj.isPalindrome();
System.out.println ("your word is Palindrome:"+isP);
}
}
class Palindrome {
private String word;
public Palindrome (String word)
{
this.word=word;
}
public boolean isPalindrome() {
String temp = "";
for(int i=word.length()-1; i!=0; i--) {
temp += word.charAt(i);
}
return ( temp.equalsIgnoreCase(word) );
}
}
2007-11-15
15:17:40
·
3 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design