12-09-2009, 10:34 PM
Hey ok so first off user FarOut is completely right you need no must use descriptive variable names. Otherwise even the best programmers will have no idea what your talking about and might give up trying to help you because you have inconvenienced them.
To answer your question though....
You are comparing a String with == this operator can only be used on primitive data types such as booleans, doubles, ints.
You need to remember even though in some instances Java treats String sort of like a primitive it is still an Object.
So instead of
if (ia2.substring(cero1,cero2) == "a")
you should use the .equals() method of the Object superclass
.equals() compares the state and vales of certain aspects of the string object.
So when you say
if (ia2.substring(cero1,cero2) == "a")
that is really just saying
if(45fa4bc45 == 783fd6709a)
those two numbers(base 16 hexadecimal) are almost never going to be the same. Without going into to much detail those numbers have to do with where the object is stored in memory on the stack or RAM.
thus using the .equals() method you can compare actual meaningful values so .. .
if (ia2.substring(cero1,cero2).equals("a"))
should return true assume all conditions are met.
also be aware of .equalsIgnoreCase(String)
might add some robustness to your program
To answer your question though....
You are comparing a String with == this operator can only be used on primitive data types such as booleans, doubles, ints.
You need to remember even though in some instances Java treats String sort of like a primitive it is still an Object.
So instead of
if (ia2.substring(cero1,cero2) == "a")
you should use the .equals() method of the Object superclass
.equals() compares the state and vales of certain aspects of the string object.
So when you say
if (ia2.substring(cero1,cero2) == "a")
that is really just saying
if(45fa4bc45 == 783fd6709a)
those two numbers(base 16 hexadecimal) are almost never going to be the same. Without going into to much detail those numbers have to do with where the object is stored in memory on the stack or RAM.
thus using the .equals() method you can compare actual meaningful values so .. .
if (ia2.substring(cero1,cero2).equals("a"))
should return true assume all conditions are met.
also be aware of .equalsIgnoreCase(String)
might add some robustness to your program