I checked all other stackoverflow links about my question but the answers there did not work. So I am asking a similar question with the hope of getting a different answer. This is the code from a class:
public String pozisyonHazirla(String param) {
String oynananHamle = param;
for (int n = 0; n < oynananHamle.length(); n++) {
if (oynananHamle.substring(n, 1).matches("[0-9]") || oynananHamle.substring(n, 1).matches(".")) {
String donothing="";
} else if (oynananHamle.substring(n, 1) == oynananHamle.substring(n, 1).toUpperCase()) {
sonuc = "Figür Hamlesi Yapıldı";
break;
} else {
sonuc = "Piyon hamlesi yapıldı";
break;
}
}
return sonuc;
}
The question is that this section of the code is not working and in 100% of the cases the iteration returns the else result which is the assigned value to the sonuc variable.
} else if (oynananHamle.substring(n, 1) == oynananHamle.substring(n, 1).toUpperCase()) {
sonuc = "Figür Hamlesi Yapıldı";
break;
My second question without opening another thread is that in the first case there is a section where I want nothing to be done if the "if" statement is viable so I put something like " String donothing ="";" . Is there anyway to improve this piece of code? Thank you in advanace for your answers and comments...
Aucun commentaire:
Enregistrer un commentaire