rutgermons
asked on
verfiy if else statement
folks
I have the following:
if (mroApp.equals("WOTRACK"))
{
mroRepName = "woprint";
}
but i want to add a statement into this:
if (mroApp.equals("WOTRACK"))
and (mroSite.equals("JFK"))
mroRepName = "woprint2";
so its an if esle
could anyone advise what the correct way
the pschuedo code is
if app =wotrack then repname=woprint else if app =wotrack and site=jfk then woprint2
all other will not have the site parameter bound
all help will do
rutger
I have the following:
if (mroApp.equals("WOTRACK"))
{
mroRepName = "woprint";
}
but i want to add a statement into this:
if (mroApp.equals("WOTRACK"))
and (mroSite.equals("JFK"))
mroRepName = "woprint2";
so its an if esle
could anyone advise what the correct way
the pschuedo code is
if app =wotrack then repname=woprint else if app =wotrack and site=jfk then woprint2
all other will not have the site parameter bound
all help will do
rutger
if (mroApp.equals("WOTRACK")
&& (mroSite.equals("JFK"))
mroRepName = "woprint2";
I think this is what u wanted.
&& (mroSite.equals("JFK"))
mroRepName = "woprint2";
I think this is what u wanted.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If the second condition is true, the first condition is also true, and so fires first - you would never get into the second test.
Reversing the tests, putting the more specific one first would work.
I would probably write it like this.
if ("WOTRACK".equals(mroApp))
mroRepName = "JFK".equals(mroSite) ? "woprint2" : "woprint";
}
Using "WOTRACK".equals(mroApp) rather than mroApp.equals("WOTRACK") makes the code more robust by avoiding a null pointer exception if mroApp is null.
I also used a ternary statement to set the value of the mroRepName variable.