error when comparing 2 string objects
hello, in the following code i try to compare to string objects, however, i dont know where is my error so please help me
Code Java:
public class Amr {
private String word;
public Amr(String str)
{
setString(str);
}
private void setString (String str)
{
this.word = str;
}
public boolean IsPloyndrome(Amr string)
{
if ( this.getString().equals(string.getString()) )
return true;
else
return false;
}
public Amr getString()
{
Amr obj = new Amr(word);
return obj;
}
}
main method:
Code Java:
public class Polyndrom
{
public static void main (String[] args)
{
Amr h = new Amr("hi");
Amr b = new Amr("hi");
if ( h.IsPloyndrome(b) )
System.out.println ("equals");
else System.out.println ("not equals");
}
}
Re: error when comparing 2 string objects
There is no need to double post your question - your other post has been removed. Next, each category has an announcements thread at the top and in it you will find explicit instructions on how to use the highlight/code tags. Next, you mention error: it helps to explain what error you are getting. You are lucky the code is somewhat straightforward that the problem is evident...look closely at how you are using the equals, you are not comparing String objects directly.
Re: error when comparing 2 string objects
Where's your main method?
Re: error when comparing 2 string objects
would you please tell me how to use ( highlight) to organize the code being displayed
Re: error when comparing 2 string objects
Quote:
Originally Posted by
amr
would you please tell me how to use ( highlight) to organize the code being displayed
See Announcements
Re: error when comparing 2 string objects