Results 1 to 3 of 3
  1. #1
    JMaste is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default Decision structure truth table

    Hi,

    if (test_1) // condition 1
    statement_1;
    else if (test_2) // condition 2
    statement_2;
    else
    if (test_3) // condition 3
    statement_3;
    else
    statement_4;

    For the structure given above the truth table is given below. I am not able to understand how they came to this truth table. Can you please explain a bit?

    Condition 1 Condition 2 Condition 3
    ----------- ----------- -----------
    1) True False False
    2) False True False
    3) False False True
    4) False False False

    Thank you.

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    Java Code:
    if (test_1) { // Condition 1  (True, False, False, False)
        statement_1;
    }
    else if (test_2) { // Condition 2 (False, True, False, False)
         statement_2;
    }
      else{ // Condition 3 (False, False, True, False)
           if (test_3) { 
               statement_3;
           }
            else{
                statement_4;
           }
    }
    Condition 1 Condition 2 Condition 3
    ----------- ----------- -----------
    1) True False False
    2) False True False
    3) False False True
    4) False False False

    I cleaned you your code a bit.

    A truth table just tells you what happens to the rest of the IF statements pending on if the IF statement is True or False. The table just lays out the possibilities.
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Actually your truth table should look like this:

    Java Code:
            Condition 1     Condition 2     Condition 3
            -----------     -----------     -----------
    1)        True             d/c             d/c
    2)        False            True            d/c
    3)        False            False           True
    4)        False            False           False
    d/c means "don't care" because if, say, Condition1 is true you don't really care what the other conditions are because the first if-statement is executed.

    kind regards,

    Jos

Similar Threads

  1. c4.5 decision tree
    By emailtosridevi in forum SWT / JFace
    Replies: 1
    Last Post: 03-15-2010, 05:34 AM
  2. Replies: 1
    Last Post: 01-08-2010, 06:19 AM
  3. Replies: 1
    Last Post: 10-20-2008, 12:58 PM
  4. Java Looping and decision
    By susan in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 04:29 AM
  5. Help with Structure
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •