I have the following code and the return is confusing me. I am new to java and not exactly sure why it is returning the way it is. Any help would be great.
When the data has PE846 and A846 it returns engine, ambo and engineambo. I’m looking to return only engineambo.
String soundString = "";
if (data.contains("PE846")) {
soundString += "engine";
betaString = "Engine : ";
sign = engine;
}
if (data.contains("A846")) {
soundString += "ambo";
betaString += "Ambo : ";
sign = ambo;
}
if (data.contains("MD846")) {
soundString += "medic";
betaString += "Medic";
sign = medic;
}
log.info(betaString + " Alerted");
{
new AudioPlayer("sounds/" + soundString + ".wav").start();
log.info(soundString);
}
You can try tracing through your code line-by-line. If it contains PE846 and A846 (but not MD846), then it will run the first two conditional blocks, thereby executing as follows: