brainfrz icon

Untitled

brainfrz | PRO | 09/22/15 11:27:41 PM UTC | 0 ⭐ | 945 👁️ | Never ⏰ | []
Java |

1.47 KB

|

None

|

0 👍

/

0 👎

/*
 *  The professor repeated multiple times variations of "You MUST set up your IF/ELSEIF structures this way – there
 *  cannot be the possibility where more than one condition might be true." Do you agree? I'm sure there must be
 *  situations that fit the following. But the set I specified proves that it's also possible for both the if and the
 *  else-if to be true, yet the logic shows it's useful to check for both. I don't understand why we MUST not have
 *  multiple cases that might potentially be true. It still compiles just fine, so it's not a syntax issue.
 */
 
public class SetTest
{
    public static void main( String[] args )
    {
        int[] set = {2, 2, 4};
 
        if (set[0] == set[1])
        {
            System.out.println("The first number is the same as the second number. I don't care " +
                                "what either number is right now.");
        }
        else if (set[0] == 2)
        {
            System.out.println("The first two numbers apparently aren't equal, and the first " +
                                "number is 2. This is useful for what I have to do in this case!");
        }
        else
        {
            System.out.println("It's good to know that the first two numbers aren't equal and " +
                                "that the first number isn't 2! Now I can do the something that " +
                                "relies on both of those facts being false.");
        }
    }
}

Comments