Sign in to follow this  

Question regarding nested ifs and conditional operator in Java

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. I hope I am posting this in the right forum. I have a general question regarding the conditional operator in Java. I have the following if statement as an example:
if (a>b){
     m=a;
}else if (c<d){
     m=c;
}else if (b>d){
    m=d;
}else{
    m=b;
}
Is there a way I can do this using a single shorthand nested if with the conditional (?) operator? I have only seen the shortcut notation used in single if/else statements before and was just curious if it could be done with nested if's. I tried experimenting with it but I cant seem to get it to work. I appreciate any help you can give me. Thanks so much!!!

Share this post


Link to post
Share on other sites

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this