brainfrz

Untitled

Sep 22nd, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. /*
  2.  *  The professor repeated multiple times variations of "You MUST set up your IF/ELSEIF structures this way – there
  3.  *  cannot be the possibility where more than one condition might be true." Do you agree? I'm sure there must be
  4.  *  situations that fit the following. But the set I specified proves that it's also possible for both the if and the
  5.  *  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
  6.  *  multiple cases that might potentially be true. It still compiles just fine, so it's not a syntax issue.
  7.  */
  8.  
  9. public class SetTest
  10. {
  11.     public static void main( String[] args )
  12.     {
  13.         int[] set = {2, 2, 4};
  14.  
  15.         if (set[0] == set[1])
  16.         {
  17.             System.out.println("The first number is the same as the second number. I don't care " +
  18.                                 "what either number is right now.");
  19.         }
  20.         else if (set[0] == 2)
  21.         {
  22.             System.out.println("The first two numbers apparently aren't equal, and the first " +
  23.                                 "number is 2. This is useful for what I have to do in this case!");
  24.         }
  25.         else
  26.         {
  27.             System.out.println("It's good to know that the first two numbers aren't equal and " +
  28.                                 "that the first number isn't 2! Now I can do the something that " +
  29.                                 "relies on both of those facts being false.");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment